根据受欢迎程度自动完成术语建议

时间:2016-05-02 10:36:56

标签: solr autocomplete solr4 solrnet

我已在我的MVC应用程序中实现了自动完成术语建议。让我解释一下我是如何做到这一点的。我在DB中创建了一个表,表格列如下:

Id  SearchTerm  CatID ResultCount Clicks Latency TermSearchTime

现在,每当用户搜索一个术语时,我们就会将其存储在此表中。下次同一个单词匹配时,我们显示术语建议。另外,作为期限普及,显示期限建议。在建议中首先显示哪个单词被更多搜索。

但是现在我也想为拼写错误的术语提供术语建议。例如,三星已存在于我的表格中。如果有人在这种情况下搜索 samsng ,那么三星应该在那里提出建议。

由于我不知道如何拼写检查SQL服务器,我决定使用Solr。

我如何使用Solr和我用SQL Db完成的默认行为?此外,请注意我从Solr获取的搜索结果。我已经索引了所有产品。我还需要索引搜索字词吗?

任何帮助都是赞赏。感谢。

1 个答案:

答案 0 :(得分:0)

在solrconfig.xml文件中检查这个以使用拼写检查处理程序。

 <requestHandler name="/spell" class="solr.SearchHandler" startup="lazy">
<lst name="defaults">
  <str name="df">text</str>
  <!-- Solr will use suggestions from both the 'default' spellchecker
       and from the 'wordbreak' spellchecker and combine them.
       collations (re-written queries) can include a combination of
       corrections from both spellcheckers -->
  <str name="spellcheck.dictionary">default</str>
  <str name="spellcheck.dictionary">wordbreak</str>
  <str name="spellcheck">on</str>
  <str name="spellcheck.extendedResults">true</str>       
  <str name="spellcheck.count">10</str>
  <str name="spellcheck.alternativeTermCount">5</str>
  <str name="spellcheck.maxResultsForSuggest">5</str>       
  <str name="spellcheck.collate">true</str>
  <str name="spellcheck.collateExtendedResults">true</str>  
  <str name="spellcheck.maxCollationTries">10</str>
  <str name="spellcheck.maxCollations">5</str>         
</lst>
<arr name="last-components">
  <str>spellcheck</str>
</arr></requestHandler>

如果不存在,则复制粘贴到您的文件中。重启solr。试试/spell?q=ipad