带约束的 Marklogic 搜索语法语法

Marklogic Search Grammar syntax with constraints

我有如下约束..有约束

<options xmlns="http://marklogic.com/appservices/search">
    <additional-query>
        <cts:and-query xmlns:cts="http://marklogic.com/cts">
            <cts:collection-query>
                <cts:uri>OncoWatch</cts:uri>
            </cts:collection-query>
        </cts:and-query>
    </additional-query>
    <constraint name="search-text">
        <word>
            <field name="wos_topic"/>
        </word>
    </constraint>
    <term>
        <term-option>case-insensitive</term-option>
        <term-option>punctuation-insensitive</term-option>
        <term-option>whitespace-insensitive</term-option>
        <term-option>wildcarded</term-option>
    </term>
</options>

当我执行搜索字符串 '(search-text:(patient* OR adult*))' 时,我得到的结果与我执行此操作时完全不同 '(search-text:patient*) OR (search-text:adult*)'.. 两者不一样吗?

如果您在搜索字符串上应用 search:parse,您可以很容易地看出区别:

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">
    <additional-query>
        <cts:and-query xmlns:cts="http://marklogic.com/cts">
            <cts:collection-query>
                <cts:uri>OncoWatch</cts:uri>
            </cts:collection-query>
        </cts:and-query>
    </additional-query>
    <constraint name="search-text">
        <word>
            <field name="wos_topic"/>
        </word>
    </constraint>
    <term>
        <term-option>case-insensitive</term-option>
        <term-option>punctuation-insensitive</term-option>
        <term-option>whitespace-insensitive</term-option>
        <term-option>wildcarded</term-option>
    </term>
</options>
return (
  search:parse("(search-text:(patient* OR adult*))", $options),
  search:parse("(search-text:patient*) OR (search-text:adult*)", $options)
)

搜索解析器支持具有 AND、OR、NEAR 等的相当复杂的搜索字符串,但缺乏将多个值输入单个约束的支持。后者才是正确的写法。第一个简单地让解析器从它的外观上混淆,结果 OR 丢失,有效地导致它搜索短语 search-text:"patient* adult*" 这有点像需要两个术语。

HTH!