好得很程序员自学网

<tfoot draggable='sEl'></tfoot>

Solr中文搜索纠错功能实现图解教程

 最近在研究solr全文搜索,功能果然很强大! 上次简单说了一下Solr环境搭建,今天说一下搜索纠错的实现 实现: 您要找的是不是[ XXX ] 功能 配置:solr3.2默认支持SpellCheck, 需要把纠错词库配置打开

编辑solrconfig.xml

[ admin @ bogon ~ ] $ vi / opt / solr / solr / conf / solrconfig . xml 

找到这面配置,把注释去掉,重启TOMCAT

编辑solrconfig.xml

  < lst name = "spellchecker" >

 

          < str name = "classname" > solr . FileBasedSpellChecker </ str >

 

          < str name = "name" > file </ str >

 

          < str name = "sourceLocation" > spellings . txt </ str >

 

          < str name = "characterEncoding" > UTF - 8 </ str >

 

          < str name = "spellcheckIndexDir" > spellcheckerFile </ str >

 

  </ lst >

 

搜[ 弯豆 ] ,就会返回[ 豌豆 ]的XML,并且搜[ wandou ],也可以返回[ 豌豆 ] XML 我用文件源的方式,在solr.home/conf/spellings.txt文件后加:"豌豆wandou"。注意一行一个词。 访问http://192.168.12.129:8983/solr/spell?q=*wandou*&spellcheck.q=

wandou&spellcheck=true&spellcheck.dictionary=file&spellcheck.build=true 返回XML

代码如下

< response >

< lst name = "responseHeader" >

< int name = "status" > 0 </ int >

< int name = "QTime" > 40 </ int >

</ lst >

< str name = "command" > build </ str >

< result name = "response" numFound = "0" start = "0" />

< lst name = "spellcheck" >

< lst name = "suggestions" >

< lst name = "wandou" >

< int name = "numFound" > 1 </ int >

< int name = "startOffset" > 0 </ int >

< int name = "endOffset" > 6 </ int >

< arr name = "suggestion" >

< str > 豌豆wandou </ str >

</ arr >

</ lst >

</ lst >

</ lst >

</ response >

 

查看更多关于Solr中文搜索纠错功能实现图解教程的详细内容...

  阅读:39次