调用search:search
不会返回预期的方面结果计数。下面是两个示例文件和我使用的代码。
Page1.xml
<pages xmlns="http://marklogic.com/docs">
<page>
<elementNode>data1</elementNode>
<textNode>text1</textNode>
</page>
<page>
<elementNode>data2</elementNode>
<textNode>text2</textNode>
</page>
<page>
<elementNode>data3</elementNode>
<textNode>text3</textNode>
</page>
<page>
<elementNode>data4</elementNode>
<textNode>text4</textNode>
</page>
</pages>
Page2.xml
<pages xmlns="http://marklogic.com/docs">
<page>
<elementNode>data5</elementNode>
<textNode>text5</textNode>
</page>
<page>
<elementNode>data6</elementNode>
<textNode>text6</textNode>
</page>
<page>
<elementNode>data7</elementNode>
<textNode>text7</textNode>
</page>
<page>
<elementNode>data8</elementNode>
<textNode>text8</textNode>
</page>
</pages>
我还创建了一个元素范围索引<elementNode>
。现在我用 searchText " text1 " 执行了 XQuery
xquery version "1.0-ml";
declare namespace html = "http://www.w3.org/1999/xhtml";
declare namespace ts= "http://marklogic.com/docs";
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">
<searchable-expression xmlns:ex="http://marklogic.com/docs">//ex:page</searchable-expression>
<grammar>
<starter strength="30" apply="grouping" delimiter=")">(</starter>
<starter strength="40" apply="prefix" element="cts:not-query">NOT</starter>
<joiner strength="10" apply="infix" element="cts:or-query" tokenize="word">OR</joiner>
<joiner strength="20" apply="infix" element="cts:and-query" tokenize="word">AND</joiner>
<joiner strength="50" apply="constraint">:</joiner>
</grammar>
<constraint name="elementNode">
<range collation="http://marklogic.com/collation/" type="xs:string">
<facet-option>limit=1000</facet-option>
<element ns="http://marklogic.com/docs" name="elementNode"/>
<searchable-expression xmlns:ex="http://marklogic.com/clover/docs-xml">//ex:elementNode</searchable-expression>
</range>
</constraint>
</options>;
let $searchResult := search:search("text1", $options)
return $searchResult
这产生了这个结果:
<search:response xmlns="" xmlns:search="http://marklogic.com/appservices/search">
<search:result index="1" uri="Page1.xml" path="fn:doc("Page1.xml")/*:pages/*:page[1]">
<search:snippet>
<search:match path="fn:doc("Page1.xml")/*:pages/*:page[1]/*:textNode">
<search:highlight>text1</search:highlight>
</search:match>
</search:snippet>
</search:result>
<search:facet name="elementNode">
<search:facet-value name="data1" count="1">data1</search:facet-value>
<search:facet-value name="data2" count="1">data2</search:facet-value>
<search:facet-value name="data3" count="1">data3</search:facet-value>
<search:facet-value name="data4" count="1">data4</search:facet-value>
</search:facet>
</search:response>
现在我在facet-result
. 它应该只返回一个方面值,即来自page1的data1 ,因为只有page1具有所需的搜索表达式“ text1 ”。而是给我整个文档中所有 textNode 值的结果。请帮助我 - 我们如何限制这一点?此外,计数给了我整个文档,但我想要的是页数匹配。facet-result