2011-09-02 90 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