gpt4 book ai didi

node.js - EdgeNGram autocomplete_filter对前缀搜索有意义吗?

转载 作者:行者123 更新时间:2023-12-03 02:16:37 27 4
gpt4 key购买 nike

我有大约一百万条记录的 Elasticsearch 索引。
我想对 Elasticsearch 索引中的2个字段,名称和ID(总共约10个)进行多前缀搜索。
创建EdgeNGram自动完成过滤器是否有意义?
或者我错过了EdgeNGram的要点。
这是我用于创建索引的代码:

client.indices.create({
index: 'testing',
// type: 'text',
body: {
settings: {
analysis: {
filter: {
autocomplete_filter: {
type: 'edge_ngram',
min_gram: 3,
max_gram: 20
}
},
analyzer: {
autocomplete: {
type: 'custom',
tokenizer: 'standard',
filter: [
'lowercase',
'autocomplete_filter'
]
}
}
}
}
}
},function(err,resp,status) {
if(err) {
console.log(err);
}
else {
console.log("create",resp);
}
});
搜索代码
client.search({  
index: 'testing',
type: 'article',
body: {
query: {
multi_match : {
query: "87041",
fields: [ "name", "id" ],
type: "phrase_prefix"
}
}
}
},function (error, response,status) {
if (error){
console.log("search error: "+error)
}
else {
console.log("--- Response ---");
console.log(response);
console.log("--- Hits ---");
response.hits.hits.forEach(function(hit){
console.log(hit);
})
}
});
搜索返回正确的结果,所以我的问题是在这种情况下创建edgengram过滤器和分析器是否有意义?
还是可以直接使用此前缀功能?
非常感谢您的信息

最佳答案

这取决于您的用例。让我解释。

  • 您可以将ngram用于此功能。假设您的数据是london bridge,那么如果您的最小克数为1而最大克数为20,则将其标记为l, lo, lon, etc.. 这样做的好处是,即使您搜索bridge或任何tokens which is part of the generated ngrams,它也会被匹配。
  • 有一个out of box feature completion suggester。它使用FST模型存储它们。甚至文档说it is faster to search but costlier to build。但认为是prefix suggester。意思是,搜索bridge默认不会带london bridge。但是有一些方法可以使这项工作。要实现的解决方法是拥有 token 数组。这里london bridgebridge是 token 。
  • 还有一种叫做context suggester。如果您知道要搜索nameid,那么最好是超过完成建议程序。当完成提示器处理所有索引时,上下文建议器根据上下文对特定索引进行处理。

  • 正如您所说的,这是前缀搜索,您可以完成它。您提到了10个这样的字段。而且,如果您知道要在最前面提出建议的 Realm ,那么可以去找上下文建议者。
    one nice answer about edge ngram and completion
    completion suggester for middle of the words-我使用了此解决方案,它的作用就像魅力。
    您可以引用文档中建议程序中可用的其他默认选项。

    关于node.js - EdgeNGram autocomplete_filter对前缀搜索有意义吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63417975/

    27 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com