Ubuntu 16.04 LTS下安装配置Solr-Mmseg4j

安装环境:Ubuntu 16.04 LTS; Java JDK 1.8.0

目录
  1. 检查系统环境
  2. 安装Apache Solr
  3. 配置solr-mmseg4j

1. 检查系统环境

  • 检查java环境
java -version

Ubuntu 16.04 LTS下安装配置Solr-Mmseg4j

所需java版本是1.8.0
相关链接:Ubuntu 16.04 LTS下安装配置Java环境

  • 系统安装更新
sudo apt-get update

2. 安装Apache Solr

Ubuntu 16.04 LTS下安装配置Solr-Mmseg4j

solr-6.5.1.tgz和solr-6.5.1.zip是一样的。这里我们下载的是solr-6.5.1.tgz

Ubuntu 16.04 LTS下安装配置Solr-Mmseg4j
  • 解压文件
tar zxvf solr-6.5.1.tgz
  • 在8080端口启动Solr 服务
cd solr-6.5.1/bin
sudo ./solr start -p 8080 -force

启动成功


Ubuntu 16.04 LTS下安装配置Solr-Mmseg4j

3. 配置solr-mmseg4j

  • 上传jar包


    Ubuntu 16.04 LTS下安装配置Solr-Mmseg4j
cd ../server/solr-webapp/webapp/WEB-INF/lib

mmseg4j-core-1.10.0.jarmmseg4j-solr-2.3.0.jar两个文件上传到/solr-6.5.1/server/solr-webapp/webapp/WEB-INF/lib路径下

Ubuntu 16.04 LTS下安装配置Solr-Mmseg4j
  • 新建一个core
    在bin目录下执行命令,生成的core0在/solr-6.5.1/server/solr/目录下
sudo ./solr create -c core0 -p 8080 -force
cd ../server/solr/core0
tree
 .
├── conf
│   ├── currency.xml
│   ├── elevate.xml
│   ├── lang
│   │   ├── contractions_ca.txt
│   │   ├── contractions_fr.txt
│   │   ├── contractions_ga.txt
│   │   ├── contractions_it.txt
│   │   ├── hyphenations_ga.txt
│   │   ├── stemdict_nl.txt
│   │   ├── stoptags_ja.txt
│   │   ├── stopwords_ar.txt
│   │   ├── stopwords_bg.txt
│   │   ├── stopwords_ca.txt
│   │   ├── stopwords_cz.txt
│   │   ├── stopwords_da.txt
│   │   ├── stopwords_de.txt
│   │   ├── stopwords_el.txt
│   │   ├── stopwords_en.txt
│   │   ├── stopwords_es.txt
│   │   ├── stopwords_eu.txt
│   │   ├── stopwords_fa.txt
│   │   ├── stopwords_fi.txt
│   │   ├── stopwords_fr.txt
│   │   ├── stopwords_ga.txt
│   │   ├── stopwords_gl.txt
│   │   ├── stopwords_hi.txt
│   │   ├── stopwords_hu.txt
│   │   ├── stopwords_hy.txt
│   │   ├── stopwords_id.txt
│   │   ├── stopwords_it.txt
│   │   ├── stopwords_ja.txt
│   │   ├── stopwords_lv.txt
│   │   ├── stopwords_nl.txt
│   │   ├── stopwords_no.txt
│   │   ├── stopwords_pt.txt
│   │   ├── stopwords_ro.txt
│   │   ├── stopwords_ru.txt
│   │   ├── stopwords_sv.txt
│   │   ├── stopwords_th.txt
│   │   ├── stopwords_tr.txt
│   │   └── userdict_ja.txt
│   ├── managed-schema
│   ├── params.json
│   ├── protwords.txt
│   ├── solrconfig.xml
│   ├── stopwords.txt
│   └── synonyms.txt
├── core.properties
└── data
    ├── index
    │   ├── segments_1
    │   └── write.lock
    ├── snapshot_metadata
    └── tlog

6 directories, 49 files

如图,conf中放的是配置文件,stopwords中放的是停用词

  • /conf/managed-schema中添加如下代码(可以使用vim编辑器直接修改)
<!-- mmseg4j-->
<field name="mmseg4j_complex_name" type="text_mmseg4j_complex" indexed="true" stored="true"/>
<field name="mmseg4j_maxword_name" type="text_mmseg4j_maxword" indexed="true" stored="true"/>
<field name="mmseg4j_simple_name" type="text_mmseg4j_simple" indexed="true" stored="true"/>

<fieldType name="text_mmseg4j_complex" class="solr.TextField" positionIncrementGap="100" >
  <analyzer>
    <tokenizer class="com.chenlb.mmseg4j.solr.MMSegTokenizerFactory" mode="complex" dicPath="/usr/local/solr-6.5.1/server/solr/my_dic"/>
    <filter class="solr.StopFilterFactory" ignoreCase="true" words="stopwords.txt" />
  </analyzer>
</fieldType>
<fieldType name="text_mmseg4j_maxword" class="solr.TextField" positionIncrementGap="100" >
  <analyzer>
    <tokenizer class="com.chenlb.mmseg4j.solr.MMSegTokenizerFactory" mode="max-word" dicPath="/usr/local/solr-6.5.1/server/solr/my_dic"/>
    <filter class="solr.StopFilterFactory" ignoreCase="true" words="stopwords.txt" />
  </analyzer>
</fieldType>
<fieldType name="text_mmseg4j_simple" class="solr.TextField" positionIncrementGap="100" >
  <analyzer>
    <tokenizer class="com.chenlb.mmseg4j.solr.MMSegTokenizerFactory" mode="simple" dicPath="/usr/local/solr-6.5.1/server/solr/my_dic"/>
    <filter class="solr.StopFilterFactory" ignoreCase="true" words="stopwords.txt" />
  </analyzer>
</fieldType>
<!-- mmseg4j-->

其中,dicPath是dic字典文件的存放路径,这里写的是绝对路径。
/usr/local/solr-6.5.1/server/solr路径下新建my_dic文件夹mkdir my_dic
然后就可以把字典文件上传到这个目录了

  • 重启solr
sudo ./solr restart -p 8080 -force

Ubuntu 16.04 LTS下安装配置Solr-Mmseg4j

安装成功
Ubuntu 16.04 LTS下安装配置Solr-Mmseg4j

参考链接:
http://lucene.apache.org/solr/quickstart.html
solr 中文分词 mmseg4j 使用例子