Solr环境搭配,配置IKAnalyzer分词
Solr下载:http://mirror.bit.edu.cn/apache/lucene/solr/
IKAnalyzer下载:https://pan.baidu.com/s/1i4VXWln
Solr环境搭配步骤:
1、安装jdk8
1、安装jdk8
2、下载solr6.0后,解压solr6.0的包。
3、解压tomcat8
4、将【solr-6.0.0\server\solr-webapp】下的webapp文件拷贝到【apache-tomcat-8.0.33\webapps】目录下,并将webapp重命名为solr(可以重命名为取任意名称)。
solr文件目录如下:

5、将【solr-6.0.0\server\lib\ext】下的所有jar包拷贝到【apache-tomcat-8.0.33\webapps\solr\WEB-INF\lib】
6、将【solr-6.0.0\server\lib\】下metrics* 开头的jar包拷贝到【apache-tomcat-8.0.33\webapps\solr\WEB-INF\lib】
7、将【solr-6.0.0\dist\】下solr-dataimporthandler-* 开头的jar包拷贝到【apache-tomcat-8.0.33\webapps\solr\WEB-INF\lib】
8、将【solr-6.0.0\server\resources】下的log4j.properties配置文件拷贝到【apache-tomcat-8.0.33\webapps\solr\WEB-INF\classes】,如果WEB-INF下没有classes文件那么 就创建一个classes文件夹。
9、在【apache-tomcat-8.0.33\webapps\solr】下新建一个文件【solrhome(文件夹名称可以任意命名)】,将【solr-6.0.0\server\solr】下的所有文件拷贝到刚刚创建
的solrhome中。
文件中包含如下:

10、修改【apache-tomcat-8.0.33\webapps\solr\WEB-INF】下的web.xml,找到如下代码:

11、运行tomcat,运行成功后访问:http://localhost:8080/solr/index.html 即可得到如下界面:

整个solr的环境搭建已经成功。(记得开启tomcat服务,不然无法访问http://localhost:8080/)
Solr创建core:
1、在sorlhome文件夹下创建【my_solr】文件夹
2、在【my_solr】文件夹中添加core.properties配置,内容如下:

这个name的值实际上就core的名称,可以任意命名,为了保证统一和方便阅读,个人觉得最好和文件夹名称一致。
3、将【solr-6.0.0\example\example-DIH\solr\solr】下的conf文件夹拷贝到【my_solr】文件夹下。包含如下文件:

【conf】中文件目录如下:

4、solr-5.0 以上默认对schema的管理是使用managed-schema,不能手动修改,需要使用Schema Restful的API操作。
如果要想手动修改配置,把【conf】文件夹中managed-schema拷贝一份修改为schema.xml,在solrconfig.xml中修改如下:

访问:http://localhost:8080/solr/index.html#/
会出现如下界面:

选择my_solr,会出现如下界面:

配置IKAnalyzer分词:
1、解压ikanalyzer-solr6.5.zip

2.把ext.dic、IKAnalyzer.cfg.xml和stopword.dic 复制到Tomcat \webapps\solr\WEB-INF\classes中,把ik-analyzer-solr5-5.x.jar 和 solr-analyzer-ik-5.1.0.jar 复制到Tomcat \webapps\solr\WEB-INF\lib中;
-
打开webapps\solr\solrhome\my_solr\conf下的schema.xml文件,在</schema> 前加入配置:
<fieldType name="text_ik" class="solr.TextField">
<analyzer type="index" isMaxWordLength="false" class="org.wltea.analyzer.lucene.IKAnalyzer"/>
<analyzer type="query" isMaxWordLength="true" class="org.wltea.analyzer.lucene.IKAnalyzer"/>
</fieldType>
<dynamicField name="*_sa" type="text_ik" indexed="true" stored="true" />
image.png
自定义域:
image.png
重启tomcat,测试:
image.png
注意:
当用slorj连接地址的时候,不能直接连接http://localhost:8080/solr/index.html#/my_solr(加入我的索引库名称为my_solr),中间不能有#号,不然会出现HTTP Status 405 - HTTP method POST is not supported by this URL的错误。正确的连接地址为:http://localhost:8080/solr/my_solr
