2013-11-26 33 views
3

我想检查查询和文档标题之间的Levenstein距离,然后按照strdist得分过滤结果。solr strdist不返回1.0的分数

的模式是:

<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? 我在做什么错?

回答

2

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

计算两个字符串之间的距离。使用Lucene拼写检查器的StringDistance接口并支持该包中的所有可用实现,并允许应用程序通过Solr的资源加载功能插入自己的实现。 strdist需要(字符串1,字符串,距离度量)

试图围绕后reading of a grokbase user谁也有类似的问题,你需要添加一个字段就像在你的架构title_raw,见下文,而REINDEX。

<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) 

正如你所看到的,我从第一个字符串删除+比较,作为计算距离时,他们也将被考虑在内。

+0

谢谢!添加了字符串字段并获得了正确的结果。 – ItayD