solr strdist 不返回 1.0 的分数

标签 solr levenshtein-distance

我想检查查询和文档标题之间的 Levenstein 距离,然后按其 strdist 分数过滤结果。

架构是:

<fields>
     <field name="id" type="string" indexed="true" stored="true" required="true" /> 
     <field name="title" type="text_general" indexed="true" stored="true" required="true" />
     <field name="_version_" type="long" indexed="true" stored="true" multiValued="false" />
</fields>

在我的索引中,我有以下文档:
{
   "id":"1",
   "title":"iPhone 4S Battery Replacement"
}

所以当我发送以下查询时:
http://localhost:8983/solr/collection1/query?q=title:iPhone+4S+Battery+Replacement&fl=*,score,lev_dist:strdist("iPhone+4S+Battery+Replacement",title,edit)

我得到:
{
    "id":"1",
    "title":"iPhone 4S Battery Replacement",
    "_version_":1452659974334316549,
    "score":6.4907703,
    "lev_dist":0.37931037
}

但我期待得到 lev_dist=1.0。为什么是 0.379?
我究竟做错了什么?

最佳答案

根据 to the docs strdist 函数需要两个字符串来比较它们。它在分析的字段上的工作方式有所不同。

Calculate the distance between two strings. Uses the Lucene spell checker StringDistance interface and supports all of the implementations available in that package, plus allows applications to plug in their own via Solr's resource loading capabilities. strdist takes (string1, string2, distance measure)



经过尝试和reading of a grokbase user谁有类似的问题,你需要添加一个字段,如 title_raw在您的架构中,请参见下文并重新编制索引。

<fields>
    <field name="id" type="string" indexed="true" stored="true" required="true" /> 
    <field name="title" type="text_general" indexed="true" stored="true" required="true" />
    <field name="title_raw" type="string" indexed="true" stored="true"  />
    <field name="_version_" type="long" indexed="true" stored="true" multiValued="false" />
</fields>

然后你会查询
query?q=title:iPhone+4S+Battery+Replacement&fl=*,score,lev_dist:strdist("iPhone 4S Battery Replacement",title_raw,edit)

如您所见,我删除了 +从要比较的第一个字符串开始,因为在计算距离时也会将它们考虑在内。

关于solr strdist 不返回 1.0 的分数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20218538/

相关文章:

python - Solr 与 solrpy 的索引问题

c# - 为什么我得到不正确的 Levenshtein 距离?

python - 使用单词列表计算 Levenshtein 距离

javascript - MongoDB部分匹配

python - django-haystack more_like_this 什么都不返回

solr - Elasticsearch-国家相似度

php - 确定两个名称是否彼此接近

algorithm - 对于不完整的字符串,是否有修改过的最小编辑距离(Levenshteina Distance)?

ruby-on-rails - 太阳黑子、Solr、order_by、编码

solr - Solr 中的可更新字段