marklogic 是否可以选择执行搜索,在文档中查找听起来与查询文本中的术语相似的单词?
我在上面找不到任何东西。所以我尝试用拼写:levenshtein-distance结合cts:tokenize和cts:words来制作自己的,你可以在这里查看它https://github.com/freshie/ml-levenshtein-search/blob/master/levenshtein-distance.xqy
这确实给了我我想要的东西......它只是给了我拼写彼此接近的单词。关于如何做听起来像搜索的任何想法?
最佳答案
最简单的方法是首先使用 cts:words()
根据语料库制作可能单词的字典。然后使用 spell:suggest-detailed()
根据查询文本查找相似的匹配项,仅限于一定距离。拼写扩展算法基于双变音位,这比 Levenshtein 更好,因为它是语音的,并且您需要类似声音而不是类似拼写。我发现将物体的距离限制在 25 可以让您获得相当程度的模糊效果。
提前:
spell:insert("dictionary.xml", spell:make-dictionary($word-sequence))
然后(0.9-ml 方言):
define function expand-spell($word as xs:string)
as xs:string*
{
let $threshold := 25
let $options := <options xmlns="http://marklogic.com/xdmp/spell">
<distance-threshold>{ $threshold }</distance-threshold>
<maximum>20</maximum>
</options>
for $suggest in spell:suggest-detailed("dictionary.xml", $word, $options)//spell:word
order by $suggest/@word-distance
return string($suggest)
}
我按距离排序,这样我就可以在演示中显示扩展,并且更接近的匹配会在列表中更高。
关于marklogic - 听起来像是在 marklogic 中搜索,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23709199/