给solr配置中文分词器
生活随笔
收集整理的这篇文章主要介绍了
给solr配置中文分词器
小编觉得挺不错的,现在分享给大家,帮大家做个参考.
Solr的中文分词器
smartcn 分词器的安装
1.首选将发行包的contrib/analysis-extras/lucene-libs/ lucene-analyzers-smartcn-4.2.0.jar复制到\solr\contrib\analysis-extras\lib下,在solr_home文件夹下 2.打开/ims_advertiesr_core/conf/scheme.xml,编辑text字段类型如下,添加以下代码到scheme.xml中的相应位置,就是找到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> 如果需要检索某个字段,还需要在scheme.xml下面的field中,添加指定的字段,用text_ smartcn作为type的名字,来完成中文分词。如 text要实现中文检索的话,就要做如下的配置: <field name ="text" type ="text_smartcn" indexed ="true" stored ="false" multiValued ="true"/>IK 分词器的安装
IKAnalyzer2012FF_u1.jar //分词器jar包 IKAnalyzer.cfg.xml //分词器配置文件 stopword.dic //分词器停词字典,可自定义添加内容中文分词器mmseg4j
mmseg4j-solr-2.3.0支持solr5.3
1.将两个jar包考入tomcat中solr项目里的lib文件内
2.配置solr_home中的schema.xml
在下面标签
里新增:
<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测试分词
在schema.xml里定义:
<field name="content_test" type="textMaxWord" indexed="true" stored="true" multiValued="true"/>然后测试:
总结
以上是生活随笔为你收集整理的给solr配置中文分词器的全部内容,希望文章能够帮你解决所遇到的问题。
- 上一篇: Servlet3.0新特性全解
- 下一篇: solr配置同义词,停止词,和扩展词库(