我有以下两个 XML 文件:
Page1.xml
<pages xmlns="http://marklogic.com/docs">
<page>
<elementNode>data1</elementNode>
<textNode>text1</textNode>
</page>
<page>
<elementNode>data1</elementNode>
<textNode>text1</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>data1</elementNode>
<textNode>text1</textNode>
</page>
<page>
<elementNode>data2</elementNode>
<textNode>text3</textNode>
</page>
<page>
<elementNode>data3</elementNode>
<textNode>text5</textNode>
</page>
<page>
<elementNode>data4</elementNode>
<textNode>text6</textNode>
</page>
<pages>
我在“elementNode”上创建了一个元素范围索引,并将“page”元素定义为片段根。我使用 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">
<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"/>
</range>
</constraint>
</options>;
let $searchResult := search:search("text1", $options)
return $searchResult
执行查询后,我得到以下响应:
<?xml version="1.0" encoding="UTF-8"?>
<search:response total="3" start="1" page-length="10" xmlns="" xmlns:search="http://marklogic.com/appservices/search">
<search:result index="1" uri="/content/C/Documents and Settings/vimleshm/Desktop/abc.xml" path="fn:doc("/content/C/Documents and Settings/vimleshm/Desktop/abc.xml")" score="22784" confidence="0.451657" fitness="0.663945">
<search:snippet>
<search:match path="fn:doc("/content/C/Documents and Settings/vimleshm/Desktop/abc.xml")/*:pages/*:page[1]">
<search:highlight>text1</search:highlight>
</search:match>
<search:match path="fn:doc("/content/C/Documents and Settings/vimleshm/Desktop/abc.xml")/*:pages/*:page[2]">
<search:highlight>text1</search:highlight>
</search:match>
</search:snippet>
</search:result>
<search:result index="2" uri="/content/C/Documents and Settings/vimleshm/Desktop/abc1.xml" path="fn:doc("/content/C/Documents and Settings/vimleshm/Desktop/abc1.xml")" score="22784" confidence="0.451657" fitness="0.663945">
<search:snippet>
<search:match path="fn:doc("/content/C/Documents and Settings/vimleshm/Desktop/abc1.xml")/*:pages/*:page[1]">
<search:highlight>text1</search:highlight>
</search:match>
</search:snippet>
</search:result>
<search:facet name="elementNode">
<search:facet-value name="data1" count="3">data1</search:facet-value>
</search:facet>
<search:qtext>text1</search:qtext>
<search:metrics>
<search:query-resolution-time>PT0S</search:query-resolution-time>
<search:facet-resolution-time>PT0.015S</search:facet-resolution-time>
<search:snippet-resolution-time>PT0S</search:snippet-resolution-time>
<search:total-time>PT0.015S</search:total-time>
</search:metrics>
</search:response>
现在你可以看到这里的“total”属性search:response
是“3”,因为我已经将“page”定义为片段根[ Marklogic Wrong count and Facet result Xquery。有什么方法可以获得正确的总数,因为“text1”只存在于 Page1.xml 和 Page2.xml 中,所以这里应该是“2”?此外,我得到了计数为“3”的 facet“data2”,它应该是“2”,因为它与前一种情况一样存在于两个 XML 文件中。请帮助我。