0

我有以下两个 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(&quot;/content/C/Documents and Settings/vimleshm/Desktop/abc.xml&quot;)" score="22784" confidence="0.451657" fitness="0.663945">
    <search:snippet>
      <search:match path="fn:doc(&quot;/content/C/Documents and Settings/vimleshm/Desktop/abc.xml&quot;)/*:pages/*:page[1]">
        <search:highlight>text1</search:highlight>
      </search:match>
      <search:match path="fn:doc(&quot;/content/C/Documents and Settings/vimleshm/Desktop/abc.xml&quot;)/*: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(&quot;/content/C/Documents and Settings/vimleshm/Desktop/abc1.xml&quot;)" score="22784" confidence="0.451657" fitness="0.663945">
    <search:snippet>
      <search:match path="fn:doc(&quot;/content/C/Documents and Settings/vimleshm/Desktop/abc1.xml&quot;)/*: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 文件中。请帮助我。

4

1 回答 1

3

您可以将片段根设置为<pages>(或无,这将默认在每个 XML 文档的根上进行分段),然后将有 2 个命中:一个在 Page1.xml 中有 2 个匹配项,一个在 Page2 中有 1 个匹配项。 xml。但是,如果您将片段根设置<page>为您所做的那样,搜索会将这些元素中的每一个视为其自己的文档,并且它将计数<page>而不是<pages>.

简单地说,结果计数将反映片段命中的数量。所以问题是你真的想计算什么?文件还是<page>s?

于 2012-10-16T22:06:46.013 回答