0

调用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(&quot;Page1.xml&quot;)/*:pages/*:page[1]">
    <search:snippet>
      <search:match path="fn:doc(&quot;Page1.xml&quot;)/*: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

4

2 回答 2

1

You use a searchable-expression, which causes search results to be portioned to those elements. Unfortunately that is not the case for facet counts, as mblakele explains. His suggestion of putting the page elements in their own document is one of two possible solutions here. The other one is defining the page element as fragment root. You can do so in the Admin interface of MarkLogic. You can find it among the database properties.

HTH!

于 2012-09-16T06:37:48.317 回答
1

索引指向文档或片段,而不是元素。这类似于 RDBMS,其中索引指向行。您的示例 XML 和代码表明您将每个文档视为关系表。而是将文档视为行。

如果示例代码与实际应用程序相似,我可能会重构文档,以便每个“页面”元素都成为自己的文档。

此外,使用http://marklogic.com/docs. MarkLogic 可能决定在将来的某个版本中使用该名称空间,这可能会给您带来问题。选择一个您有合理期望控制的命名空间。

于 2012-09-16T01:46:08.853 回答