1.下载mmseg4j
mmseg4j-core:核心库文件;
mmseg4j-solr:solr支持库文件;
mmseg4j-analysis:分析库文件;
下载地址:http://mvnrepository.com/search?q=mmseg4j
参考地址:https://github.com/chenlb/mmseg4j-solr
参考地址:https://code.google.com/p/mmseg4j/downloads/list
目前mmseg4j官网不提供新版本下载,在maven库选择下载;
solr4.0以上版本请下载mmseg4j1.9.0以上版本;
选择mmseg4j1.9.1下载;
2.拷贝(mmseg4j-core-1.9.1.jar、mmseg4j-solr-1.9.1.jar、mmseg4j-analysis-1.9.1.jar)到tomcat下的webapps/solr/WEB-INF/lib;
3.在solr的home目录新建dic字典目录;
4.配置solr中文分词器
打开solr的home目录的collection1/conf/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="../dic" /><!--此处为分词器词典所处位置-->
</analyzer>
</fieldtype>
添加到<types></types>里面;
5.修改中文分词器字段
把<fields></fields>里的
<field name="title" type="text_general" indexed="true" stored="true" multiValued="true"/>
<field name="subject" type="text_general" indexed="true" stored="true"/>
<field name="description" type="text_general" indexed="true" stored="true"/>
<field name="comments" type="text_general" indexed="true" stored="true"/>
<field name="author" type="text_general" indexed="true" stored="true"/>
<field name="keywords" type="text_general" indexed="true" stored="true"/>
替换为
<field name="title" type="textComplex" indexed="true" stored="true" multiValued="true"/>
<field name="subject" type="textComplex" indexed="true" stored="true"/>
<field name="description" type="textComplex" indexed="true" stored="true"/>
<field name="comments" type="textComplex" indexed="true" stored="true"/>
<field name="author" type="textComplex" indexed="true" stored="true"/>
<field name="keywords" type="textComplex" indexed="true" stored="true"/>
6.打开solr管理界面,选择左侧collection1的Analysis页面;
Analyse Fieldname / FieldType选择textComplex;
注:
针对mmseg4j-analysis.jar的bug处理
错误:
TokenStream contract violation: reset()/close() call missing, reset() called multiple times, or subclass does not call super.reset(). Please see Javadocs of TokenStream class for more information about the correct consuming workflow.
下载地址:https://code.google.com/p/mmseg4j/downloads/list
下载mmseg4j-1.9.1.zip,解压得到里面的mmseg4j-analysis文件夹;
找到MMSegTokenizer.java,修改reset()方法;
public void reset() throws IOException {
//lucene 4.0
//org.apache.lucene.analysis.Tokenizer.setReader(Reader)
//setReader 自动被调用, input 自动被设置。
super.reset(); //加这一句
mmSeg.reset(input);
}
修改后运行mvn clean package -DskipTests进行打包得到最新的mmseg4j-analysis-1.9.1.jar 并替换tomcat下solr的WEB-INF/lib/mmseg4j-analysis-1.9.1.jar。
mmseg4j-core:核心库文件;
mmseg4j-solr:solr支持库文件;
mmseg4j-analysis:分析库文件;
下载地址:http://mvnrepository.com/search?q=mmseg4j
参考地址:https://github.com/chenlb/mmseg4j-solr
参考地址:https://code.google.com/p/mmseg4j/downloads/list
目前mmseg4j官网不提供新版本下载,在maven库选择下载;
solr4.0以上版本请下载mmseg4j1.9.0以上版本;
选择mmseg4j1.9.1下载;
2.拷贝(mmseg4j-core-1.9.1.jar、mmseg4j-solr-1.9.1.jar、mmseg4j-analysis-1.9.1.jar)到tomcat下的webapps/solr/WEB-INF/lib;
3.在solr的home目录新建dic字典目录;
4.配置solr中文分词器
打开solr的home目录的collection1/conf/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="../dic" /><!--此处为分词器词典所处位置-->
</analyzer>
</fieldtype>
添加到<types></types>里面;
5.修改中文分词器字段
把<fields></fields>里的
<field name="title" type="text_general" indexed="true" stored="true" multiValued="true"/>
<field name="subject" type="text_general" indexed="true" stored="true"/>
<field name="description" type="text_general" indexed="true" stored="true"/>
<field name="comments" type="text_general" indexed="true" stored="true"/>
<field name="author" type="text_general" indexed="true" stored="true"/>
<field name="keywords" type="text_general" indexed="true" stored="true"/>
替换为
<field name="title" type="textComplex" indexed="true" stored="true" multiValued="true"/>
<field name="subject" type="textComplex" indexed="true" stored="true"/>
<field name="description" type="textComplex" indexed="true" stored="true"/>
<field name="comments" type="textComplex" indexed="true" stored="true"/>
<field name="author" type="textComplex" indexed="true" stored="true"/>
<field name="keywords" type="textComplex" indexed="true" stored="true"/>
6.打开solr管理界面,选择左侧collection1的Analysis页面;
Analyse Fieldname / FieldType选择textComplex;
注:
针对mmseg4j-analysis.jar的bug处理
错误:
TokenStream contract violation: reset()/close() call missing, reset() called multiple times, or subclass does not call super.reset(). Please see Javadocs of TokenStream class for more information about the correct consuming workflow.
下载地址:https://code.google.com/p/mmseg4j/downloads/list
下载mmseg4j-1.9.1.zip,解压得到里面的mmseg4j-analysis文件夹;
找到MMSegTokenizer.java,修改reset()方法;
public void reset() throws IOException {
//lucene 4.0
//org.apache.lucene.analysis.Tokenizer.setReader(Reader)
//setReader 自动被调用, input 自动被设置。
super.reset(); //加这一句
mmSeg.reset(input);
}
修改后运行mvn clean package -DskipTests进行打包得到最新的mmseg4j-analysis-1.9.1.jar 并替换tomcat下solr的WEB-INF/lib/mmseg4j-analysis-1.9.1.jar。