欢迎投稿

今日深度:

初学solr,

初学solr,



启动solr,运行techproducts示例,使用smartcn中文分词包,加载mmseg4j中文分词包(solr7.3.1)

1. 启动错误

在下载解压完solr后,遇到的第一个问题是启动不了solr,执行以下指令后

bin/solr start -e techproducts

出现如下错误:

启动错误
经过查找资料,solr默认不允许root用户进行操作,而通过

ls -l

我们可以发现目录的拥有者是root


image

在非root账户下,在solr的上一级目录,使用如下指令修改solr目录的拥有者

sudo chown -R 用户:用户组 solr-7.3.1/

此时在启动solr,就会发现一切OK

2. 启动techproducts样例

输入以下指令启动样例

bin/solr start -e techproducts

启动成功

image
在本地电脑浏览器中输入以下地址访问Solr Admin UI(将localhost换成云服务器的公网IP,有风险,只要他人知道公网IP,即可操作你的solr)

http://localhost:8983/solr
image

基础查询

image

分面查询

界面上找不到的参数在下面的方框中输入

image
image
image
网页查询页面(包括分面查询)
image

3. Solr配置中文分词包smartcn

/usr/src/solr-7.3.1/contrib/analysis-extras/lucene-libs
  1. 在/usr/src/solr-7.3.1/example/techproducts/solr/techproducts/conf下的solrconfig.xml中添加如下语句,加载smartcn包
<lib dir="${solr.install.dir:../../../..}/contrib/analysis-extras/lucene-libs/"
regex="lucene-analyzers-smartcn-\d.*\.jar" />
  1. 在/usr/src/solr-7.3.1/example/techproducts/solr/techproducts/conf下的managed-schema中,新建一个字段类型text_chinese,用以处理中文分词。
<fieldType name="text_chinese" class="solr.TextField" positionIncrementGap="100">
    <analyzer>
        <tokenizer class="org.apache.lucene.analysis.cn.smart.HMMChineseTokenizerFactory"/>
    </analyzer>
</fieldType>

中文分词效果


image

中英文混合分词效果

image

新词处理

image

从新词处理可以看出smartcn有很大的缺陷,对于新的中文词,只能将其按字进行分词。

4. Solr配置中文分词包mmseg4j和词典文件

    <fieldtype name="textComplex" class="solr.TextField" positionIncrementGap="100">
      <analyzer>
          <tokenizer class="com.chenlb.mmseg4j.solr.MMSegTokenizerFactory" mode="complex" 
              dicPath="/usr/src/solr-7.3.1/example/techproducts/solr/techproducts/dic"/>
      </analyzer>
    </fieldtype>
    <fieldtype name="textMaxWord" class="solr.TextField" positionIncrementGap="100">
      <analyzer>
          <tokenizer class="com.chenlb.mmseg4j.solr.MMSegTokenizerFactory" mode="max-word" 
              dicPath="/usr/src/solr-7.3.1/example/techproducts/solr/techproducts/dic"/>
      </analyzer>
    </fieldtype>
    <fieldtype name="textSimple" class="solr.TextField" positionIncrementGap="100">
      <analyzer>
          <tokenizer class="com.chenlb.mmseg4j.solr.MMSegTokenizerFactory" mode="simple" 
              dicPath="/usr/src/solr-7.3.1/example/techproducts/solr/techproducts/dic" />
      </analyzer>
    </fieldtype>
  1. 重启solr服务器
  2. 进入solr Amdin界面,使用textSimple模式
    image
  3. 如上所示,小目标、老司机、洪荒之力、吃瓜群众、蓝瘦香菇等词被拆分,在word.dic文件末尾,根据我们目标的分词效果,添加自定义词汇,添加完之后,再次重启solr服务器
    image
    最终的分词效果如图:
    image

www.htsjk.Com true http://www.htsjk.com/solr/39225.html NewsArticle 初学solr, 启动solr,运行techproducts示例,使用smartcn中文分词包,加载mmseg4j中文分词包(solr7.3.1) 1. 启动错误 在下载解压完solr后,遇到的第一个问题是启动不了solr,执行以下指令后...
相关文章
    暂无相关文章
评论暂时关闭