2011-09-02 91 views
3

我有一个供应商信息的数据库:名称和地址(地址,城市,邮编和国家/地区)。我需要搜索这个数据库并返回一些供应商。在搜索框中,用户可以输入任何内容:供应商的名称,地址的一部分,城市,邮编,......如果我找不到任何结果,我需要实施谷歌,如“你的意思是“功能给用户一个建议。基于多个字段的Solr/Lucene拼写检查建议

我想过使用Solr/Lucene来做到这一点。我已经安装了Solr,使用CSV文件导出了我需要的信息,并基于此文件创建了索引。现在我可以使用solr.SpellCheckComponent从Solr字段获取建议。事情是我的建议是基于单一领域,需要它从地址,城市,邮编,国家和名称字段获取信息。

在Solr的配置文件,我有这样的事情:

<searchComponent name="spellcheck" class="solr.SpellCheckComponent"> 
<str name="queryAnalyzerFieldType">textSpell</str> 

<lst name="spellchecker"> 
    <str name="name">default</str> 
    <str name="field">name</str> 
    <str name="spellcheckIndexDir">spellchecker</str> 
</lst> 
</searchComponent> 

<requestHandler name="/spell" class="solr.SearchHandler" startup="lazy"> 
    <lst name="defaults"> 
     <str name="spellcheck.onlyMorePopular">false</str> 
     <str name="spellcheck.extendedResults">false</str> 
     <str name="spellcheck.count>1</str> 
    </lst> 
    <arr name="last-components"> 
     <str>spellcheck</str> 
    </arr> 
</requestHandler> 

我可以运行类似的查询:

http://localhost:8983/solr/spell?q=some_company_name&spellcheck=true&spellcheck.collate=true&spellcheck.build=true 

有谁知道如何改变我的配置文件,以具有多项建议字段?

谢谢!

回答

6

您在schema.xml中为此使用了复制字段。 <copyField source="*" dest="contentSpell"/>会将所有字段复制到contentSpell。

然后将<str name="field">name</str>更改为<str name="field">contentSpell</str>您将从各个领域得到建议。

+0

谢谢!它为我工作! – nepomucenobr

6

为了配置Solr的拼写检查使用的话从几个领域,你应该:

  1. 声明一个新的领域。新字段声明应该使用属性type =“textSpell”和multiValued =“true”。例如:<field name="didYouMean" type="textSpell" indexed="true" multiValued="true"/>
  2. 将所有字段(其单词应该是拼写检查索引的一部分)复制到新字段中。例如:<copyField source="field1" dest="didYouMean"/> <copyField source="field2" dest="didYouMean"/>
  3. 配置Solr以使用新字段。通过设置字段名称来使用您的拼写检查字段名称。例如:<str name="field">didYouMean</str>

更多和详细信息,请访问Solr spellcheck compound from several fields