Marklogic:搜索:对短语提出建议

Marklogic:搜索:对短语提出建议,marklogic,Marklogic,我有以下xml结构: <root> <text>Hi i am a test user and doing testing here. Copied text Let’s suppose we have a text field where the user needs to enter the number of a person id. If the user types 1, all ids starting with 1 will show up. If the

我有以下xml结构:

<root>
<text>Hi i am a test user and doing testing here. Copied text Let’s suppose we have a text field where the user needs to enter the number of a person id. If the user types 1, all ids starting with 1 will show up. If the user types 12, all ids starting with 12 will show up.</text>
</root>

嗨,我是一个测试用户,在这里做测试。复制的文本假设我们有一个文本字段,用户需要在其中输入个人id的编号。如果用户键入1,则将显示所有以1开头的id。如果用户键入12,则将显示以12开头的所有ID。
现在,我已经在“text”元素上创建了字段,并在其上启用了字段词词典。执行以下查询:

xquery version "1.0-ml"; 
import module namespace search ="http://marklogic.com/appservices/search" at "/MarkLogic/appservices/search/search.xqy"; 
let $options := 
<search:options xmlns="http://marklogic.com/appservices/search">
 <default-suggestion-source>
    <word collation="http://marklogic.com/collation//S2">
      <field name="text"/>
    </word>
 </default-suggestion-source>
</search:options>
return
search:suggest("tes", $options, 100)
xquery版本“1.0-ml”;
导入模块命名空间搜索=”http://marklogic.com/appservices/search“在“/MarkLogic/appservices/search/search.xqy”;
let$options:=
返回
搜索:建议(“tes”,$options,100)

因此,我得到了“测试”和“测试”的建议,这是绝对好的,但我也希望在上面的情况下,我期待着更多的文本“测试用户和做…”和“测试在这里…”。请在这方面帮助我。

单词词典存储单词标记,这就是返回单个单词而不是短语的原因。对于短语内的匹配,您可以在
上使用范围索引,对于每个搜索建议条目
concat(“*”,$term,“*”)
,因此您的API调用将如下所示
search:suggest(“*tes*”,$options,100)

但是,由于使用了领先的通配符模式,我认为这会大大降低查询速度,并且还会返回元素的整个值,而不是从搜索词的位置开始,即:
Hi我是一个测试用户,正在这里进行测试。复制的文本…
测试用户并执行…
。当然,您可以通过编程的方式解析出来


<>为了更好的性能,考虑使用块元素范围索引策略。它需要预处理和潜在的大量数据,这取决于区块源的大小,但它将实现您想要的结果,并且非常快速和可扩展。有一个详细说明如何执行此操作的示例。

要搜索部分短语,请使用开头双引号(的语法值),而不使用结尾引号。 例如:search:suggest('and th',$options) “还有那个” “还有这个” 结尾的双引号向解析器发出短语完整且正确的信号 因此,未生成扩展建议。 也与约束一起使用

search:suggest('constraint:"and th', $options)</search:quotation>
search:suggest('constraint:'and th',$options)
===== 从