zoukankan      html  css  js  c++  java
  • 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 ,在tomcatwebapps目录下新建solr文件夹;

    2)将 solr 压缩包中 solrserversolr-webappwebapp文件夹下文件复制到Tomcatwebappssolr目录下 ;

    3)将 solr 压缩包中 solrserverlibext 中的 jar 全部复制到 TomcatwebappssolrWEB-INFlib 目录中; 

    4)将solr压缩包中solr/server/lib/metrics* 开头的jar全部复制到 Tomcat webappssolrWEB-INFlib 目录中; 

    5)将solr压缩包中solr/dist/solr-dataimporthandler-* 开头的jar全部复制到 Tomcat webappssolrWEB-INFlib 目录中; 

    6)在TomcatwebappssolrWEB-INF下建立classes目录,并将solr/server/resources/log4j.properties文件复制其中;

    7)在D盘根目录下建立solrhome文件夹(也可以放在其它目录中)

    8)复制solr/server/solr/* 所有文件到D:/solrhome目录,用到创建solr的core时使用。

    3、配置Solr:

     (1)修改Tomcat 9.0webappssolrWEB-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.0webappssolrWEB-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的文件夹,将solrserversolrconfigsetssample_techproducts_configs下的conf全部复制到core1,注意修改core.properties这个文件里的name一定要跟core1一致,如下图

    2.打开浏览器http://localhost:8080/solr/index.html#/

    点击Add Core,如图 

    
    
     

    3.下载IKAnalyzer,将jar文件复制到Tomcat webappssolrWEB-INFlib中,同时将IKAnalyzer.cfg.xml、stopword.dic文件复制到D:/solrhome/core1/conf文件夹下

    4. 在 solr_homemycore1confschema.xml 增加如下配置

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

     最后就可以使用text_ik了

  • 相关阅读:
    rsyslog 存储到 mysql
    LAMP 建立 Wordpress 站点 Linux Apache MariaDB PHP
    CentOS 6.9 CentOS 7.4 自动安装系统 kickstart
    shell编程, 100文钱买100只鸡, 简单实现
    创建私有CA, 加密解密基础, PKI, SSL
    运维派 企业面试题6 防dos攻击
    运维派 企业面试题4&5 创建10个 用户 ; ping探测主机是否在线
    运维派 企业面试题3 为上题中的 "十个随机字母_test.html" 文件 更名
    运维派 企业面试题2 创建10个 "十个随机字母_test.html" 文件
    MongoDB释放磁盘空间
  • 原文地址:https://www.cnblogs.com/johnwood/p/6673694.html
Copyright © 2011-2022 走看看