我需要为一个集合中的 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 个字符时,才会发生这种情况。我该如何解决这个问题?