【问题标题】:MarkLogic Search With Constraint Returning Wrong Result带约束的 MarkLogic 搜索返回错误结果
【发布时间】:2018-05-10 05:34:19
【问题描述】:
xquery version "1.0-ml";

import module namespace
  search = "http://marklogic.com/appservices/search"
  at "/MarkLogic/appservices/search/search.xqy";

let $options := 
  <options xmlns="http://marklogic.com/appservices/search">
    <constraint name="city">
      <value>
        <element  name="city"/>
      </value>
    </constraint>
    <sort-order type="xs:string" collation="http://marklogic.com/collation/"
      direction="ascending">
      <element ns="" name="userName"/>
    </sort-order>
  </options>
return search:search("city : Atlanta", $options)

当我在 qconsole 上使用 city : Atlanta 执行上述查询时,我得到了正确的匹配文档详细信息(即 2 个匹配项),但是当我使用上述查询执行 city NE Atlanta 时,我得到了错误的结果......这意味着得到所有ML 中可用的文档。

我的要求是当我通过 city NE Atlanta 它应该显示零匹配而不是显示来自 ML 的所有文档。

我也不想为 city 创建 Range 索引,因为该字段可能会在运行时更改。

如果我错了,请纠正我。

【问题讨论】:

    标签: marklogic marklogic-8


    【解决方案1】:

    在文档搜索中,比较仅适用于范围查询。

    搜索 API 忽略无效查询,生成一个空查询,该查询匹配数据库中的所有文档。

    但是,否定查询可用于值查询,方法是在约束前加上减号(如“-city:Atlanta”),产生:

    <cts:not-query xmlns:cts="http://marklogic.com/cts">
      <cts:element-value-query>
        <cts:element>city</cts:element>
        <cts:text xml:lang="en">Atlanta</cts:text>
      </cts:element-value-query>
    </cts:not-query>
    

    该查询是否检索到您期望的文档?

    希望对您有所帮助,

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-11-16
      • 2014-08-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-11-10
      • 1970-01-01
      相关资源
      最近更新 更多