Solr7.5.0配置中文分词器IKAnalyzer

   摘要:IKAnalyzer最后更新是在2012年,对于高版本的lucee不支持。但网上还是有被修改过的IkAnalyzer的6.5.0版本,试了下可以支持lucene7.x整合到solr7.x中也没什么问题

1、下载IKAnalyzer6.5.0.zip压缩包      下载链接:https://pan.baidu.com/s/1Vfd5UggL1awc-LtQBm2ypQ

2、打开WinSCP,把我们下载好的安装包,上传到Linux服务器的 /usr/local/software/目录下

          为了便于管理,我们先在Linux服务器上新建一个/usr/local/software 文件夹,专门用于存放安装包

[root@localhost ~]# mkdir -p /usr/local/software


 

3、使用putty连接到我们的Linux服务器,进入到software/ 目录下,解压IKAnalyzer6.5.0.zip

[root@localhost ~]# cd /usr/local/software/           //进入到software目录下

[root@localhost software]# ls       //查看software目录
fastDFS_software     nginx_software  solr_software
IKAnalyzer6.5.0.zip  redis-5.0.0     tomcat9
jdk1.8               redis-cluster   zookeeper-3.4.13

[root@localhost software]# unzip IKAnalyzer6.5.0.zip &>/dev/null      //解压IKAnalyzer

[root@localhost software]# ls     
fastDFS_software  IKAnalyzer6.5.0.zip  nginx_software  redis-cluster  tomcat9
IKAnalyzer6.5.0   jdk1.8               redis-5.0.0     solr_software  zookeeper-3.4.13

[root@localhost software]# rm -rf IKAnalyzer6.5.0.zip      //删除IKAnalyzer6.5.0.zip压缩包

4、进入到IKAnalyzer6.5.0目录中,拷贝IKAnalyzer6.5.0.jar 到tomcat的 webapps/solr/WEB-INF/lib/ 目录下

[root@localhost software]# cd IKAnalyzer6.5.0/      //进入到IKAnalyzer6.5.0目录下

[root@localhost IKAnalyzer6.5.0]# ls       //查看IKAnalyzer6.5.0目录
doc      IKAnalyzer6.5.0.jar  IKAnalyzer╓╨╬─╖╓┤╩╞ўV2012_FF╩╣╙├╩╓▓с.pdf  NOTICE.txt
ext.dic  IKAnalyzer.cfg.xml   LICENSE.txt                               stopword.dic

[root@localhost IKAnalyzer6.5.0]# cp IKAnalyzer6.5.0.jar /usr/local/software/tomcat9/webapps/solr/WEB-INF/lib/      //拷贝IKAnalyzer6.5.0.jar 到tomcat的 webapps/solr/WEB-INF/lib/ 目录下

5、在tomcat的 webapps/solr/WEB-INF 目录下创建一个classes文件夹

[root@localhost IKAnalyzer6.5.0]# cd /usr/local/software/tomcat9/webapps/solr/WEB-INF/    //进入到WEB-INF目录下

[root@localhost WEB-INF]# ls    //查看WEB-INF目录
lib  web.xml

[root@localhost WEB-INF]# mkdir classes    //创建classes文件夹

[root@localhost WEB-INF]# ls
classes  lib  web.xml

6、把IKAnalyzer6.5.0目录下的 ext.dic、IKAnalyzer.cfg.xml、stopword.dic三个文件拷贝到classes目录下

[root@localhost WEB-INF]# cd /usr/local/software/IKAnalyzer6.5.0/    //进入到IKAnalyzer6.5.0目录下

[root@localhost IKAnalyzer6.5.0]# ls     //查看IKAnalyzer6.5.0目录
doc      IKAnalyzer6.5.0.jar  IKAnalyzer╓╨╬─╖╓┤╩╞ўV2012_FF╩╣╙├╩╓▓с.pdf  NOTICE.txt
ext.dic  IKAnalyzer.cfg.xml   LICENSE.txt                               stopword.dic

[root@localhost IKAnalyzer6.5.0]# cp ext.dic IKAnalyzer.cfg.xml stopword.dic /usr/local/software/tomcat9/webapps/solr/WEB-INF/classes/      //拷贝到classes目录下

7、进入到/solr_home/solr_core目录下,修改managed-schema文件,配置中文分词器 (fieldType)和 业务域 (field)

[root@localhost IKAnalyzer6.5.0]# cd /usr/local/software/solr_software/solr_home/solr_core/conf/

[root@localhost conf]# ls
lang  managed-schema  params.json  protwords.txt  solrconfig.xml  stopwords.txt  synonyms.txt

[root@localhost conf]# vim managed-schema

使用shift+g跳转到managed-schema文件末尾,在末尾添加如下代码片段      注意:添加的代码片段要在</schema>之前

type="text_ik" :表示使用分词     

indexed:指定该字段是否索引,接收值为 true 和 false,字符串类型默认为true,其他的数据类型默认为false。值为true的话会先做分词再索引,值为false的话不分词,原样写入索引中。

stored="true":表示进行存储

<fieldType name="text_ik" class="solr.TextField">
   <analyzer class="org.wltea.analyzer.lucene.IKAnalyzer"/>
</fieldType>

<field name="item_title" type="text_ik" indexed="true" stored="true"/>
<field name="item_sell_point" type="text_ik" indexed="true" stored="true"/>
<field name="item_price" type="plong" indexed="true" stored="true"/>
<field name="item_image" type="string" indexed="false" stored="true"/>
<field name="item_category_name" type="string" indexed="true" stored="true"/>
<field name="item_desc" type="text_ik" indexed="true" stored="false"/>

<field name="item_keywords" type="text_ik" indexed="true" stored="false" multiValued="true"/>
<copyField source="item_title" dest="item_keywords"/>
<copyField source="item_sell_point" dest="item_keywords"/>
<copyField source="item_category_name" dest="item_keywords"/>
<copyField source="item_desc" dest="item_keywords"/>

8、启动tomcat     如果tomcat已经启动,需要关掉再重新启动

[root@localhost solr_core]# cd /usr/local/software/tomcat9/bin/

[root@localhost bin]# ./startup.sh

9、打开浏览器,在地址栏中输入192.168.30.1:8080/solr/index.html,进入到solr的管理页面,点击Core Selector,选择我们之前创建的solr_core

10、下面我们来测试中文分词器是否可用,我们在Field Value当中添加一段中文,然后选择item_title字段,最后点击"Analyse Values"蓝色按钮,就可以开始分析了,分析结果如下。可以看到,我们的中文分析器配置成功了。

            

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值