Solr 的安装和部署

Solr 安装和部署

  1. 下载 Solr 安装包并解压
  2. 创建 Solr 的家目录E:\solr\solrHome
  3. D:\software\solr-x.x.x\example\solr下的所有文件拷贝到E:\solr\solrHome
  4. D:\software\solr-x.x.x下的contrib 和 dist拷贝到E:\solr\下,与 solrHome 同级
  5. 修改 E:\solr\solrHome\collection1\conf\solrconfig.xml

    <!-- 
      调整引用的 jar 文件的路径,这里仅给出了一对修改的样例,所有类似这样的都需要修改
      引用的 jar 文件在 solrHome 同级的 contrib 和 dist 目录下
      solr.install.dir:表示 collection1 所在的目录 solrHome
    -->
    <!-- 原内容: -->
    <lib dir="${solr.install.dir:../../../}/contrib/extraction/lib" regex=".*\.jar" />
    <lib dir="${solr.install.dir:../../../}/dist/" regex="solr-cell-\d.*\.jar" />
    <!-- 修改后: --> 
    <lib dir="${solr.install.dir:../}/contrib/extraction/lib" regex=".*\.jar" />
    <lib dir="${solr.install.dir:../}/dist/" regex="solr-cell-\d.*\.jar" />
    
    <!-- 配置查询时返回的数据格式 -->
    <requestHandler name="/select" class="solr.SearchHandler">
    <lst name="defaults">
        <str name="echoParams">explicit</str>
        <int name="rows">10</int><!--显示数量-->
        <str name="wt">json</str><!--显示格式-->
        <str name="df">text</str><!--默认搜索字段-->
    </lst>
    </requestHandler>
  6. D:\software\solr-x.x.x\dist下的 solr.war 拷贝到 tomcat 的 webapps 下,改名为 solr.war,启动 tomcat

  7. D:\software\solr-x.x.x\example\lib\ext下的所有 jar 文件拷贝到 tomcat 下的webapps\solr\WEB-INF\lib
  8. 修改webapps\solr\WEB-INF\web.xml

    <!-- 放开这段代码,修改 env-entry-value,如下 -->
    <env-entry>
       <env-entry-name>solr/home</env-entry-name>
       <env-entry-value>e:\solr\solrHome</env-entry-value>
       <env-entry-type>java.lang.String</env-entry-type>
    </env-entry>
  9. D:\software\solr-x.x.x\example\resources\log4j.properties拷贝到webapps\solr\WEB-INF\classes

  10. 重启 tomcat,访问http://localhost:8080/solr

配置 IK 中文分词器

  1. 下载 IK 中文分词器
  2. 将 jar 文件拷贝到E:\solr\contrib\IKAnalyzer\lib,IKAnalyzer 和 lib 文件夹需要创建
  3. 将 jar 文件拷贝到 tomcat 下webapps\solr\WEB-INF\lib
  4. 修改 E:\solr\solrHome\collection1\conf\solrconfig.xml
  5. IKAnalyzer.cfg.xml、ext_stopword.dic、mydict.dic拷贝到 tomcat 下webapps\solr\WEB-INF\classes
  6. 修改E:\solr\solrHome\collection1\conf\schema.xml

    <!-- IKAnalyzer-->
    <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>

自定义 fieldType 和 field

以商品信息为例:

修改 schema.xml 文件

<!-- 定义分词时使用的类型,这里是 IK 分词器提供的类型 -->
<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>
<!-- 定义域,注意 type,如果属性需要分词的话,type 使用上面定义的 fieldType -->
<field name="goods_name" type="text_ik" indexed="true" stored="true"/>
<field name="goods_category_id" type="string" indexed="true" stored="true"/>
<field name="goods_category_name" type="text_ik" indexed="true" stored="true"/>
<field name="goods_price"  type="float" indexed="true" stored="true"/>
<field name="goods_description" type="text_ik" indexed="true" stored="false"/>
<field name="goods_picture" type="string" indexed="false" stored="true"/>
<!-- 定义关键词搜索域 -->   
<field name="goods_keywords" type="text_ik" indexed="true" stored="false" multiValued="true"/>
<!-- 定义关键词搜索域要搜索的范围,例如这里的范围是 goods_name 和 goods_description-->  
<copyField source="goods_name" dest="goods_keywords"/>
<copyField source="goods_description" dest="goods_keywords"/>

Solr 解压后的文件及解释

这里写图片描述

bin:可执行程序、脚本
contrib:存放了一些扩展的包,用于索引和搜索
dist:其中有一个solr-4.10.3.war 将其部署到tomcat容器中,运行solr
docs:使用说明文档
example:存储了很多solr开发使用的例子工程及目录结构等。
   example/solr:
    该目录是一个包含了默认配置信息的Solr的Core目录。
   example/multicore:
    该目录包含了在Solr的multicore中设置的多个Core目录。 
   example/webapps:
    该目录中包括一个solr.war,该war可作为solr的运行实例工程。
licenses:solr相关的一些许可信息

licenses:许可

猜你喜欢

转载自blog.csdn.net/qq_30038111/article/details/80063807