我在尝试将搜索参数指定为仅搜索文件中的特定xml元素时遇到问题。这是我用来搜索的文件:
<file>
<title>red</title>
<info>
<section>blurbs</section>
<section>words</section>
</info>
<info>
<section>first</section>
<section>this</section>
</info>
<info>
<section>blue</section>
<section>green</section>
</info>
<info>
<section>red</section>
<section>yellow</section>
</info>
</file>
搜索:我正在使用的搜索查询是:
xquery version "1.0-ml";
import module namespace search = "http://marklogic.com/appservices/search"
at "/MarkLogic/appservices/search/search.xqy";
let $options :=
<options xmlns="http://marklogic.com/appservices/search">
<additional-query>
<cts:document-query depth="infinity" xmlns:cts="http://marklogic.com/cts">
<cts:uri>/test_data/test_search.xml</cts:uri>
</cts:document-query>
</additional-query>
<extract-document-data selected="include">
<extract-path>/file/info</extract-path>
</extract-document-data>
<constraint>
<word>
<element name="info"/>
</word>
</constraint>
<search-option>filtered</search-option>
</options>
let $results := search:search("red", $options)
$ results变量包含:
<search:response snippet-format="snippet" total="1" start="1" page-length="10" selected="include" xmlns:search="http://marklogic.com/appservices/search">
<search:result index="1" uri="/test_data/test_search.xml" path="fn:doc("/test_data/test_search.xml")" score="8448" confidence="0.4065818" fitness="0.8925228">
<search:snippet>
<search:match path="fn:doc("/test_data/test_search.xml")/file">
<search:highlight>red
</search:highlight>
</search:match>
<search:match path="fn:doc("/test_data/test_search.xml")/file/info[4]">
<search:highlight>red
</search:highlight>
</search:match>
</search:snippet>
<search:extracted kind="element">
<info>
<section>blurbs
</section>
<section>words
</section>
</info>
<info>
<section>first
</section>
<section>this
</section>
</info>
<info>
<section>blue
</section>
<section>green
</section>
</info>
<info>
<section>red
</section>
<section>yellow
</section>
</info>
</search:extracted>
</search:result>
<search:qtext>red
</search:qtext>
<search:metrics>
<search:query-resolution-time>PT0.00166S
</search:query-resolution-time>
<search:snippet-resolution-time>PT0.000992S
</search:snippet-resolution-time>
<search:extract-resolution-time>PT0.00049S
</search:extract-resolution-time>
<search:total-time>PT0.003748S
</search:total-time>
</search:metrics>
</search:response>
正如您所看到的那样,标题和信息会出现红色,但我只想搜索xml信息元素。我在这里做错了什么?
编辑:我对搜索IE搜索的约束条件有一点了解:搜索(“标题:红色”)但是当该约束是多个单词时会发生什么?答案 0 :(得分:1)
创建约束时,应为其指定名称,如:
<constraint name="inf">
这就是可以在inf:red
有关详细信息,请参阅:
您还可以使用search:term元素:
为未标记的搜索字词指定默认处理方式要理解从查询文本生成的查询,将debug或return-query选项设置为true会很有帮助:
顺便说一句,您可以使用fn:doc()来检索任何文档并使用XPath或search:snippet()从文档中提取节点。搜索:search()函数不是为按URI检索文档而设计的。
最后,如果可能,您可能需要修改文档模型。 MarkLogic可以为以下文档提供更有用的索引:
希望有帮助,