我有以下xml文档,其中包含三个专利分配标记
<patent-assignments>
<patent-assignment>
<patent-assignors>
<patent-assignor>
<name>TSAI, YU-WEN</name>
</patent-assignor>
</patent-assignors>
<patent-assignees>
<patent-assignee>
<name>FARADAY TECHNOLOGY CORP.</name>
</patent-assignee>
</patent-assignees>
</patent-assignment>
<patent-assignment>
<patent-assignors>
<patent-assignor>
<name>APPLE</name>
</patent-assignor>
</patent-assignors>
<patent-assignees>
<patent-assignee>
<name>GOOGLE INC</name>
</patent-assignee>
</patent-assignees>
</patent-assignment>
<patent-assignment>
<patent-assignors>
<patent-assignor>
<name>GOOGLE INC</name>
</patent-assignor>
</patent-assignors>
<patent-assignees>
<patent-assignee>
<name>FARADAY TECHNOLOGY CORP.</name>
</patent-assignee>
</patent-assignees>
</patent-assignment>
</patent-assignments>
现在,当我运行以下搜索查询时: -
import module namespace search="http://marklogic.com/appservices/search" at
"/Marklogic/appservices/search/search.xqy";
declare variable $options:=
<options xmlns="http://marklogic.com/appservices/search">
<transform-results apply="raw"/>
</options>;
search:search("apple", $options, 1, 1)/search:result
我将完整文档作为输出,但匹配的单词“APPLE”仅在xml的第二个专利分配标签中。我想只获得第二项专利分配作为输出而不是完整的文件。如果我使用片段,那么它会显示找到匹配项的文档和元素名称,但它不会返回实际输出。我希望将特定的专利分配标签作为找到匹配单词的输出。
答案 0 :(得分:3)
Puneet,搜索:搜索功能正在完成它所配置的功能,在这种意义上,响应是正确的。你只需要对你要求它做的改变做一点。试试这个:
import module namespace search="http://marklogic.com/appservices/search" at
"/Marklogic/appservices/search/search.xqy";
declare variable $options:=
<options xmlns="http://marklogic.com/appservices/search">
<transform-results apply="raw"/>
<searchable-expression>/patent-assignments/patent-assignment</searchable-expression>
</options>;
search:search("apple", $options, 1, 1)/search:result
添加searchable-expression元素后,我只返回与查询匹配的专利赋值元素:
<search:result index="1" uri="/patent.xml" path="fn:doc("/patent.xml")/patent-assignments/patent-assignment[2]" score="43008" confidence="0.664889" fitness="0.664889" xmlns="" xmlns:search="http://marklogic.com/appservices/search">
<patent-assignment>
<patent-assignors>
<patent-assignor>
<name>APPLE</name>
</patent-assignor>
</patent-assignors>
<patent-assignees>
<patent-assignee>
<name>GOOGLE INC</name>
</patent-assignee>
</patent-assignees>
</patent-assignment>
</search:result>