【问题标题】:Query Returning False Positive查询返回误报
【发布时间】:2014-12-04 06:14:44
【问题描述】:

我正在使用以下查询来获取记录,但它正在获取误报结果。

<cts:and-query xmlns:cts="http://marklogic.com/cts">
    <cts:or-query>
      <cts:element-value-query>
        <cts:element>type</cts:element>
        <cts:text xml:lang="en">article</cts:text>
      </cts:element-value-query>
    </cts:or-query>
    <cts:element-query>
      <cts:element>body</cts:element>
      <cts:word-query>
        <cts:text xml:lang="en">ace???</cts:text>
        <cts:option>case-insensitive</cts:option>
        <cts:option>diacritic-insensitive</cts:option>
        <cts:option>punctuation-insensitive</cts:option>
        <cts:option>whitespace-insensitive</cts:option>
        <cts:option>stemmed</cts:option>
        <cts:option>wildcarded</cts:option>
      </cts:word-query>
    </cts:element-query>
    <cts:or-query>
      <cts:element-range-query operator="&gt;=">
        <cts:element>expires-on</cts:element>
        <cts:value xsi:type="xs:dateTime" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">2014-12-04T06:05:29.78Z</cts:value>
      </cts:element-range-query>
      <cts:not-query>
    <cts:element-value-query>
      <cts:element>expires-on</cts:element>
      <cts:text xml:lang="en">*</cts:text>
      <cts:option>wildcarded</cts:option>
    </cts:element-value-query>
      </cts:not-query>
    </cts:or-query>
  </cts:and-query>
</results>

上面的查询是一个通配符查询,应该搜索从“ace”开始的 6 个字母的单词。但我们也得到了包含超过 6 个以“ace”开头的字母单词的结果。

以下是我们使用的索引

  1. 单词搜索
  2. 词位
  3. 快速短语搜索
  4. 快速区分大小写的搜索
  5. 快速变音符号敏感搜索
  6. 快速元素词搜索
  7. 元素词位置
  8. 快速元素词组搜索
  9. 三个字符搜索
  10. 快速元素字符搜索
  11. 尾随通配符搜索
  12. 快速元素尾随通配符搜索

我们还在执行搜索时使用了“未过滤”选项。

任何帮助将不胜感激。

谢谢

【问题讨论】:

    标签: marklogic


    【解决方案1】:

    你没有说你的通配符索引设置是什么。这很重要:如果索引不包含正确的信息,结果将与您的期望不符。

    查看https://docs.marklogic.com/guide/search-dev/wildcard 以了解各种通配符索引的工作原理以及您可能想要启用的索引。在这种情况下,我建议使用trailing-wildcard,也许还有element-trailing-wildcard

    也可以通过一些优化策略来改进该查询。如果可能的话,我会避免使用element-value-query*。而是使用cts:element-query($qname, cts:and-query(()))。它做同样的工作,而且效率更高。

    如果body 是一个简单的元素,那么使用element-word-query for 而不是将element-queryword-query 组合起来会更有效。如果body 很复杂——也就是说,如果要匹配的文本在后代元素中——那么您可以选择使用启用尾随通配符位置索引的元素查询,或者为所有后代设置element word query through元素。

    【讨论】:

    • 这可能是因为您在元素查询中嵌入单词查询的方式。您可以添加尾随通配符位置索引,这可能会修复它,但如果您可以优化查询会更好。
    • 根据您的建议,我们将查询更改为以下查询 cts:element-word-query(xs:QName("body"), ("ace??"), ("case- insensitive","diacritic-insensitive","punctuation-insensitive","whitespace-insensitive","stemmed","wildcarded","lang=en"), 1) 查询没有获取任何结果,虽然我有很多与查询匹配的单词。
    • 这可能意味着您的单词在 body 元素的后代中:element-word-query 仅匹配命名元素的文本子元素。您可以使用 element-word-query-through 配置来解决这个问题:docs.marklogic.com/guide/admin/text_index#id_93943 - 但在这种情况下,可能有很好的论据来添加尾随通配符位置索引。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-03-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-11-17
    • 2014-02-15
    • 1970-01-01
    相关资源
    最近更新 更多