1,下载对应jar包,并拷贝到sorl服务器的lib目录底下shell
2,添加配置文件(在Solr的安装部署及简单使用已经有过介绍)服务器
<fieldtype name="textComplex" class="solr.TextField" positionIncrementGap="100"> <analyzer> <tokenizer class="com.chenlb.mmseg4j.solr.MMSegTokenizerFactory" mode="complex" dicPath="d:\solr\my_dic"/> </analyzer> </fieldtype> <fieldtype name="textMaxWord" class="solr.TextField" positionIncrementGap="100"> <analyzer> <tokenizer class="com.chenlb.mmseg4j.solr.MMSegTokenizerFactory" mode="max-word" /> </analyzer> </fieldtype> <fieldtype name="textSimple" class="solr.TextField" positionIncrementGap="100"> <analyzer> <tokenizer class="com.chenlb.mmseg4j.solr.MMSegTokenizerFactory" mode="simple" dicPath="dic" /> </analyzer> </fieldtype>
其中 dicPath="d:\solr\my_dic" 是咱们指定的词库路径,词库文件都在这个文件夹底下,而且名字要以words开头,以dic作后缀,例如 words_my.dic。做为演示,在词库里添加.net
爱他美 高富帅
值得强调的是:这个词典文件必须是utf-8格式的,不然没法识别。code
3,重启solr服务,进入管理界面xml
先试一下没有添加自定义词库的效果,输入文字:高富帅喜欢德国爱他美奶粉(使用textSimple)blog
再试一下添加了自定义词库的效果,仍是上面的文字token
明显添加了自定义词库的显示效果要比没添加好不少utf-8