window下配置Solr6.5以及IK Analyzer分词配置
一、安装准备及各软件使用版本说明:
1.下载jdk,我下载的版本是jdk-8u121-windows-x64.exe,下载地址:
http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html
2.下载tomcat,我下载的版本为apache-tomcat-9.0.0.M19.exe,下载地址:
http://tomcat.apache.org/download-90.cgi?Preferred=http%3A%2F%2Fmirror.bit.edu.cn%2Fapache%2F
3.下载solr6.5,下载地址:
http://mirrors.tuna.tsinghua.edu.cn/apache/lucene/solr/6.5.0/
二、Solr安装与配置:
1)解压下载的solr ,在tomcat\webapps\目录下新建solr文件夹;
2)将 solr 压缩包中 solr\server\solr-webapp\webapp文件夹下文件复制到Tomcat\webapps\solr目录下 ;
3)将 solr 压缩包中 solr\server\lib\ext 中的 jar 全部复制到 Tomcat\webapps\solr\WEB-INF\lib 目录中;
4)将solr压缩包中solr/server/lib/metrics* 开头的jar全部复制到 Tomcat\ webapps\solr\WEB-INF\lib 目录中;
5)将solr压缩包中solr/dist/solr-dataimporthandler-* 开头的jar全部复制到 Tomcat\ webapps\solr\WEB-INF\lib 目录中;
6)在Tomcat\webapps\solr\WEB-INF\下建立classes目录,并将solr/server/resources/log4j.properties文件复制其中;
7)在D盘根目录下建立solrhome文件夹(也可以放在其它目录中)
8)复制solr/server/solr/* 所有文件到D:/solrhome目录,用到创建solr的core时使用。
3、配置Solr:
(1)修改\Tomcat 9.0\webapps\solr\WEB-INF的web.xml文件,去掉下面这段代码的注释
<env-entry>
<env-entry-name>solr/home</env-entry-name> <env-entry-value>D:/solrhome</env-entry-value> //将路径指向我们创建的solrhome目录。 <env-entry-type>java.lang.String</env-entry-type> </env-entry>
(2)修改\Tomcat 9.0\webapps\solr\WEB-INF的web.xml文件,注释下面这段代码(权限相关的配置)
<!-- <security-constraint> <web-resource-collection> <web-resource-name>Disable TRACE</web-resource-name> <url-pattern>/</url-pattern> <http-method>TRACE</http-method> </web-resource-collection> <auth-constraint/> </security-constraint> <security-constraint> <web-resource-collection> <web-resource-name>Enable everything but TRACE</web-resource-name> <url-pattern>/</url-pattern> <http-method-omission>TRACE</http-method-omission> </web-resource-collection> </security-constraint> -->
(3)完整的配置如下
<?xml version="1.0" encoding="UTF-8"?> <!-- Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright ownership. The ASF licenses this file to You under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. --> <web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" version="2.5" metadata-complete="true" > <!-- Uncomment if you are trying to use a Resin version before 3.0.19. Their XML implementation isn't entirely compatible with Xerces. Below are the implementations to use with Sun's JVM. <system-property javax.xml.xpath.XPathFactory= "com.sun.org.apache.xpath.internal.jaxp.XPathFactoryImpl"/> <system-property javax.xml.parsers.DocumentBuilderFactory= "com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderFactoryImpl"/> <system-property javax.xml.parsers.SAXParserFactory= "com.sun.org.apache.xerces.internal.jaxp.SAXParserFactoryImpl"/> --> <!-- People who want to hardcode their "Solr Home" directly into the WAR File can set the JNDI property here... --> <env-entry> <env-entry-name>solr/home</env-entry-name> <env-entry-value>D:/solrhome</env-entry-value> <env-entry-type>java.lang.String</env-entry-type> </env-entry> <!-- Any path (name) registered in solrconfig.xml will be sent to that filter --> <filter> <filter-name>SolrRequestFilter</filter-name> <filter-class>org.apache.solr.servlet.SolrDispatchFilter</filter-class> <!-- Exclude patterns is a list of directories that would be short circuited by the SolrDispatchFilter. It includes all Admin UI related static content. NOTE: It is NOT a pattern but only matches the start of the HTTP ServletPath. --> <init-param> <param-name>excludePatterns</param-name> <param-value>/libs/.+,/css/.+,/js/.+,/img/.+,/tpl/.+</param-value> </init-param> </filter> <filter-mapping> <!-- NOTE: When using multicore, /admin JSP URLs with a core specified such as /solr/coreName/admin/stats.jsp get forwarded by a RequestDispatcher to /solr/admin/stats.jsp with the specified core put into request scope keyed as "org.apache.solr.SolrCore". It is unnecessary, and potentially problematic, to have the SolrDispatchFilter configured to also filter on forwards. Do not configure this dispatcher as <dispatcher>FORWARD</dispatcher>. --> <filter-name>SolrRequestFilter</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> <servlet> <servlet-name>LoadAdminUI</servlet-name> <servlet-class>org.apache.solr.servlet.LoadAdminUiServlet</servlet-class> </servlet> <!-- Remove in Solr 5.0 --> <!-- This sends SC_MOVED_PERMANENTLY (301) for resources that changed in 4.0 --> <servlet> <servlet-name>RedirectOldAdminUI</servlet-name> <servlet-class>org.apache.solr.servlet.RedirectServlet</servlet-class> <init-param> <param-name>destination</param-name> <param-value>${context}/#/</param-value> </init-param> </servlet> <servlet> <servlet-name>RedirectOldZookeeper</servlet-name> <servlet-class>org.apache.solr.servlet.RedirectServlet</servlet-class> <init-param> <param-name>destination</param-name> <param-value>${context}/admin/zookeeper</param-value> </init-param> </servlet> <servlet> <servlet-name>RedirectLogging</servlet-name> <servlet-class>org.apache.solr.servlet.RedirectServlet</servlet-class> <init-param> <param-name>destination</param-name> <param-value>${context}/#/~logging</param-value> </init-param> </servlet> <servlet> <servlet-name>SolrRestApi</servlet-name> <servlet-class>org.restlet.ext.servlet.ServerServlet</servlet-class> <init-param> <param-name>org.restlet.application</param-name> <param-value>org.apache.solr.rest.SolrSchemaRestApi</param-value> </init-param> </servlet> <servlet-mapping> <servlet-name>RedirectOldAdminUI</servlet-name> <url-pattern>/admin/</url-pattern> </servlet-mapping> <servlet-mapping> <servlet-name>RedirectOldAdminUI</servlet-name> <url-pattern>/admin</url-pattern> </servlet-mapping> <servlet-mapping> <servlet-name>RedirectOldZookeeper</servlet-name> <url-pattern>/zookeeper.jsp</url-pattern> </servlet-mapping> <servlet-mapping> <servlet-name>RedirectOldZookeeper</servlet-name> <url-pattern>/zookeeper</url-pattern> </servlet-mapping> <servlet-mapping> <servlet-name>RedirectLogging</servlet-name> <url-pattern>/logging</url-pattern> </servlet-mapping> <servlet-mapping> <servlet-name>LoadAdminUI</servlet-name> <url-pattern>/old.html</url-pattern> </servlet-mapping> <servlet-mapping> <servlet-name>LoadAdminUI</servlet-name> <url-pattern>/index.html</url-pattern> </servlet-mapping> <servlet-mapping> <servlet-name>SolrRestApi</servlet-name> <url-pattern>/schema/*</url-pattern> </servlet-mapping> <mime-mapping> <extension>.xsl</extension> <!-- per http://www.w3.org/TR/2006/PR-xslt20-20061121/ --> <mime-type>application/xslt+xml</mime-type> </mime-mapping> <welcome-file-list> <welcome-file>/index.html</welcome-file> </welcome-file-list> <!-- Get rid of error message --> <!-- <security-constraint> <web-resource-collection> <web-resource-name>Disable TRACE</web-resource-name> <url-pattern>/</url-pattern> <http-method>TRACE</http-method> </web-resource-collection> <auth-constraint/> </security-constraint> <security-constraint> <web-resource-collection> <web-resource-name>Enable everything but TRACE</web-resource-name> <url-pattern>/</url-pattern> <http-method-omission>TRACE</http-method-omission> </web-resource-collection> </security-constraint> --> </web-app>
在浏览器上运行 http://localhost:8080/solr/index.html#/
三、索引以及IK分词配置
1.创建索引区,在D:/solrhome文件夹下建一个名为core1的文件夹,将solr\server\solr\configsets\sample_techproducts_configs下的conf全部复制到core1,注意修改core.properties这个文件里的name一定要跟core1一致,如下图
2.打开浏览器http://localhost:8080/solr/index.html#/
点击Add Core,如图
3.下载IKAnalyzer,将jar文件复制到Tomcat\ webapps\solr\WEB-INF\lib中,同时将IKAnalyzer.cfg.xml、stopword.dic文件复制到D:/solrhome/core1/conf文件夹下
4. 在 solr_home\mycore1\conf\schema.xml 增加如下配置
<fieldType name="text_ik" class="solr.TextField"> <analyzer class="org.wltea.analyzer.lucene.IKAnalyzer"/> </fieldType>
最后就可以使用text_ik了