Solr5.0配置中文分词包

来源:互联网 发布:mac平时要关机吗 编辑:程序博客网 时间:2024/05/01 16:25

Solr中默认的中文分词是用Lucene的一元分词包。
现在说明在Solr5.0中配置Lucene的SmartCN中文分词包。

1,进入Solr的安装目录,我这里是:/root/nutch/solr-5.0.0
把contrib/analysis-extras/lucene-libs/lucene-analyzers-smartcn-5.0.0.jar包复制到solr的启动目录的lib目录下。

# cp ./contrib/analysis-extras/lucene-libs/lucene-analyzers-smartcn-5.0.0.jar  ./server/solr-webapp/webapp/WEB-INF/lib/

2,修改managed-schema配置文件。此文件在/root/nutch/solr-5.0.0/server/solr/mycore1/conf目录下,其中mycore1是建立的core名称。
在/root/nutch/solr-5.0.0/server/solr/mycore1/conf/managed-schema配置文件中添加如下信息:#vi managed-schema

<fieldType name="text_smart" class="solr.TextField" positionIncrementGap="100">        <analyzer type="index">         <!-- 此处需要配置主要的分词类 -->          <tokenizer class="solr.SmartChineseSentenceTokenizerFactory"/>          <!--            <filter class="solr.StopFilterFactory" ignoreCase="true" words="stopwords.txt" enablePositionIncrements="true" />          <filter class="solr.LowerCaseFilterFactory"/>           -->          <!-- in this example, we will only use synonyms at query time          <filter class="solr.SynonymFilterFactory" synonyms="index_synonyms.txt" ignoreCase="true" expand="false"/>        -->          <filter class="solr.SmartChineseWordTokenFilterFactory"/>        </analyzer>        <analyzer type="query">        <!-- 此处配置同上 -->          <tokenizer class="solr.SmartChineseSentenceTokenizerFactory"/>              <!--           <filter class="solr.StopFilterFactory" ignoreCase="true" words="stopwords.txt" enablePositionIncrements="true" />          <filter class="solr.SynonymFilterFactory" synonyms="synonyms.txt" ignoreCase="true" expand="true"/>          <filter class="solr.LowerCaseFilterFactory"/>          -->          <filter class="solr.SmartChineseWordTokenFilterFactory"/>        </analyzer>      </fieldType>  
<field name="_text_smart" type="text_smart" indexed="true" stored="true" multiValued="true"/>

3,重启solr服务

# ./bin/solr restartSending stop command to Solr running on port 8983 ... waiting 5 seconds to allow Jetty process 50325 to stop gracefully.Waiting to see Solr listening on port 8983 [\]  Started Solr server on port 8983 (pid=50745). Happy searching!

4,验证
用SmartCN的分词。
这里写图片描述

用Solr默认的分词。
这里写图片描述

0 0
原创粉丝点击