给solr配置中文分词器
生活随笔
收集整理的這篇文章主要介紹了
给solr配置中文分词器
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
Solr的中文分詞器
smartcn 分詞器的安裝
1.首選將發(fā)行包的contrib/analysis-extras/lucene-libs/ lucene-analyzers-smartcn-4.2.0.jar復(fù)制到\solr\contrib\analysis-extras\lib下,在solr_home文件夾下 2.打開/ims_advertiesr_core/conf/scheme.xml,編輯text字段類型如下,添加以下代碼到scheme.xml中的相應(yīng)位置,就是找到fieldType定義的那一段,在下面多添加這一段就好啦 <fieldType name="text_smartcn" class="solr.TextField" positionIncrementGap="0"><analyzer type="index"><tokenizer class="org.apache.lucene.analysis.cn.smart.SmartChineseSentenceTokenizerFactory"/><filter class="org.apache.lucene.analysis.cn.smart.SmartChineseWordTokenFilterFactory"/></analyzer><analyzer type="query"><tokenizer class="org.apache.lucene.analysis.cn.smart.SmartChineseSentenceTokenizerFactory"/><filter class="org.apache.lucene.analysis.cn.smart.SmartChineseWordTokenFilterFactory"/></analyzer> </fieldType> 如果需要檢索某個(gè)字段,還需要在scheme.xml下面的field中,添加指定的字段,用text_ smartcn作為type的名字,來(lái)完成中文分詞。如 text要實(shí)現(xiàn)中文檢索的話,就要做如下的配置: <field name ="text" type ="text_smartcn" indexed ="true" stored ="false" multiValued ="true"/>IK 分詞器的安裝
IKAnalyzer2012FF_u1.jar //分詞器jar包 IKAnalyzer.cfg.xml //分詞器配置文件 stopword.dic //分詞器停詞字典,可自定義添加內(nèi)容中文分詞器mmseg4j
mmseg4j-solr-2.3.0支持solr5.3
1.將兩個(gè)jar包考入tomcat中solr項(xiàng)目里的lib文件內(nèi)
2.配置solr_home中的schema.xml
在下面標(biāo)簽
里新增:
<fieldtype name="textComplex" class="solr.TextField" positionIncrementGap="100"> <analyzer> <tokenizer class="com.chenlb.mmseg4j.solr.MMSegTokenizerFactory" mode="complex" dicPath="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="n:/custom/path/to/my_dic" /> </analyzer> </fieldtype>重啟tomcat測(cè)試分詞
在schema.xml里定義:
<field name="content_test" type="textMaxWord" indexed="true" stored="true" multiValued="true"/>然后測(cè)試:
總結(jié)
以上是生活随笔為你收集整理的给solr配置中文分词器的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Servlet3.0新特性全解
- 下一篇: solr配置同义词,停止词,和扩展词库(