1

我需要为一个集合中的 json 文档创建分页搜索。文件结构:

{
   "Id": "OBJ-0000",
   "Title": "sample text",
   "Visible": true
}

我在字段 Id、Title 和 Visible 以及搜索选项 xml 配置上创建了元素范围索引:

<?xml  version="1.0" encoding="UTF-8"?>
<search:options xmlns:search="http://marklogic.com/appservices/search">
  <search:constraint name="id">
    <search:range facet="false" type="xs:string">
      <search:json-property>Id</search:json-property>
    </search:range>
  </search:constraint>
  <search:constraint name="title">
    <search:range facet="false" type="xs:string">
      <search:json-property>Title</search:json-property>
    </search:range>
  </search:constraint>
  <search:constraint name="visible">
    <search:value type="boolean">
      <search:json-property>Visible</search:json-property>
    </search:value>
  </search:constraint>
  <search:operator name="sort">
    <search:state name="idAsc">
      <search:sort-order direction="ascending">
        <search:json-property>Id</search:json-property>
      </search:sort-order>
    </search:state>
    <search:state name="idDesc">
      <search:sort-order direction="descending">
        <search:json-property>Id</search:json-property>
      </search:sort-order>
    </search:state>
    <search:state name="titleAsc">
      <search:sort-order direction="ascending">
        <search:json-property>Title</search:json-property>
      </search:sort-order>
      <search:sort-order direction="descending">
        <search:json-property>Id</search:json-property>
      </search:sort-order>
    </search:state>
    <search:state name="titleDesc">
      <search:sort-order direction="descending">
        <search:json-property>Title</search:json-property>
      </search:sort-order>
      <search:sort-order direction="descending">
        <search:json-property>Id</search:json-property>
      </search:sort-order>
    </search:state>
    <search:state name="isvisibleAsc">
      <search:sort-order direction="ascending">
        <search:json-property>Visible</search:json-property>
      </search:sort-order>
      <search:sort-order direction="descending">
        <search:json-property>Id</search:json-property>
      </search:sort-order>
    </search:state>
    <search:state name="isvisibleDesc">
      <search:sort-order direction="descending">
        <search:json-property>Visible</search:json-property>
      </search:sort-order>
      <search:sort-order direction="descending">
        <search:json-property>Id</search:json-property>
      </search:sort-order>
    </search:state>
  </search:operator>
  <search:return-results>true</search:return-results>
  <search:return-metrics>false</search:return-metrics>
  <search:transform-results apply="raw">
  </search:transform-results>
  <search:debug>false</search:debug>
</search:options>

之后,我参考选项文件创建了 POST 请求:

LATEST/search?format=json&pageLength=20&start=1&options=objectSearch   

结构化查询:

 {
    "query": {
      "operator-state": {
        "operator-name": "sort",
        "state-name": "TitleAsc"
      },
      "and-query": {
        "term-query": { "text": "*exam*" }
      }
    }
}

它有效。但是,但是,当我使用参数start=1进行查询时,在“total”中我得到的结果比实际结果要多,但是如果我指定start=20例如,“total”计算正确。仅当我在搜索词中首先使用带有通配符 (*) 的搜索参数并且词包含超过 3 个字符时,才会发生这种情况。我该如何解决这个问题?

4

1 回答 1

2

从文档中:

https://docs.marklogic.com/search:search

search:search 的输出返回一个元素,该元素又包含一个总属性。total 属性的值是一个估计值,基于查询的索引分辨率,并且没有为准确性进行过滤。索引解析的准确性取决于数据库的索引配置、查询以及正在搜索的数据。

这意味着只有为您的查询打开所有必要的索引时,您才会收到准确的总数。

在此处使用推荐的通配符索引设置应该可以帮助您获得准确的总数:https ://docs.marklogic.com/guide/search-dev/wildcard#id_14163

从您上面的评论中,您似乎在代码点排序规则中缺少一个单词词典。

于 2018-06-05T13:26:04.363 回答