gpt4 book ai didi

elasticsearch 模糊匹配 max_expansions & min_similarity

转载 作者:行者123 更新时间:2023-11-29 02:44:01 26 4
gpt4 key购买 nike

我在我的项目中使用模糊匹配,主要是为了查找同名的拼写错误和不同拼写。我需要准确理解 Elasticsearch 的模糊匹配是如何工作的,以及它如何使用标题中提到的 2 个参数。

据我所知,min_similarity 是查询字符串与数据库中字符串匹配的百分比。我找不到有关如何计算此值的确切说明。

据我所知,ma​​x_expansions 是应该执行搜索的 Levenshtein 距离。如果这实际上是 Levenshtein 距离,那将是我的理想解决方案。无论如何,它不起作用例如我有单词“Samvel”

queryStr      max_expansions         matches?
samvel 0 Should not be 0. error (but levenshtein distance can be 0!)
samvel 1 Yes
samvvel 1 Yes
samvvell 1 Yes (but it shouldn't have)
samvelll 1 Yes (but it shouldn't have)
saamvelll 1 No (but for some weird reason it matches with Samvelian)
saamvelll anything bigger than 1 No

文档说了一些我实际上不理解的内容:

Add max_expansions to the fuzzy query allowing to control the maximum number 
of terms to match. Default to unbounded (or bounded by the max clause count in
boolean query).

所以请任何人向我解释这些参数究竟如何影响搜索结果。

最佳答案

min_similarity 是介于零和一之间的值。来自 Lucene 文档:

For example, for a minimumSimilarity of 0.5 a term of the same length 
as the query term is considered similar to the query term if the edit
distance between both terms is less than length(term)*0.5

所指的“编辑距离”是 Levenshtein distance .

这个查询在内部工作的方式是:

  • 在考虑min_similarity 时,它会找到索引中存在的所有可以匹配搜索词的词
  • 然后它会搜索所有这些字词。

你可以想象这个查询会有多繁重!

为了解决这个问题,您可以设置 max_expansions 参数来指定应考虑的最大匹配项数。

关于elasticsearch 模糊匹配 max_expansions & min_similarity,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7148615/

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