solr 6.3.0 使用

注:

  1. 文章只是记录操作步骤,不适合入门教学
  2. 直接利用内置的jetty,不使用tomcat

下载

  • 从官网仓库下载zip包 : solr-6.3.0.zip , 解压到E:\solr-6.3.0。

配置jar包

  • 在E:\solr-6.3.0\contrib下新建文件夹db\libik\lib,将mysql数据库的驱动包mysql-connector-java-5.1.40.jar和ik中文分词器的jar包ik-analyzer-solr-6.3.0.jar分别拷贝到E:\solr-6.3.0\contrib\db\lib和E:\solr-6.3.0\contrib\ik\lib文件夹下。

创建core

  • 在E:\solr-6.3.0\bin目录下,启动控制台,使用命令行solr create -c products -d basic_configs的创建一个名为products的core,创建的core在E:\solr-6.3.0\server\solr目录下

配置core

  • 在E:\solr-6.3.0\server\solr\products\conf目录下

配置managed-schema

  • 将如下内容注释掉
<field name="id" type="string" indexed="true" stored="true" required="true" multiValued="false" />
  • 搜索uniqueKey并把值改为product_id
<uniqueKey>product_id</uniqueKey>
  • 在配置文件末尾(</schema>之前),添加如下配置
    <!-- 配置ik中文分词器 -->
    <fieldType name="text_ik" class="solr.TextField" positionIncrementGap="100">
      <analyzer type="index">
        <tokenizer class="org.wltea.analyzer.lucene.IKTokenizerFactory" useSmart="false"/>
        <filter class="solr.LowerCaseFilterFactory"/>
      </analyzer>
      <analyzer type="query">
        <tokenizer class="org.wltea.analyzer.lucene.IKTokenizerFactory" useSmart="true"/>
        <filter class="solr.LowerCaseFilterFactory"/>
      </analyzer>
    </fieldType>


    <!-- 属性 -->
    <field name="product_id" type="string" indexed="true" stored="true" required="true" />
    <field name="product_name" type="text_ik" indexed="true" stored="true" />
    <field name="product_catalog" type="int" indexed="false" stored="true" />
    <field name="product_catalog_name" type="string" indexed="true" stored="false" />
    <field name="product_price" type="tfloat" indexed="true" stored="true" />
    <field name="product_description" type="text_ik" indexed="true" stored="false" />
    <field name="product_picture" type="string" indexed="false" stored="true" />
    <field name="product_keywords" type="text_ik" indexed="true" stored="false" multiValued="true" />

    <copyField source="product_name" dest="product_keywords" />
    <copyField source="product_description" dest="product_keywords" />

配置data-config.xml

  • 新建data-config.xml配置文件,内容如下:
<?xml version="1.0" encoding="UTF-8" ?>
<dataConfig>
  <dataSource
    driver="com.mysql.jdbc.Driver"
    type="JdbcDataSource"
    url="jdbc:mysql://localhost:3306/solr?useSSL=true"
    user="root"
    password="13061079"
    />
  <document>
    <entity name="product" query="SELECT pid,name,catalog,catalog_name,price,description,picture FROM products ">
      <field column="pid" name="product_id"/>
      <field column="name" name="product_name"/>
      <field column="catalog" name="product_catalog"/>
      <field column="catalog_name" name="product_catalog_name"/>
      <field column="price" name="product_price"/>
      <field column="description" name="product_description"/>
      <field column="picture" name="product_picture"/>
    </entity>
  </document>
</dataConfig>

配置solrconfig.xml

  • 在lib标签附近添加如下配置
 <!-- 导入jar包 -->
  <lib dir="${solr.install.dir:../../../..}/contrib/dataimporthandler/lib" regex=".*\.jar" />
  <lib dir="${solr.install.dir:../../../..}/dist/" regex="solr-dataimporthandler-\d.*\.jar" />

  <!-- 连接数据库jar包 -->
  <lib dir="${solr.install.dir:../../../..}/contrib/db/lib" regex=".*\.jar" />

  <!-- ik分词器jar包 -->
  <lib dir="${solr.install.dir:../../../..}/contrib/ik/lib" regex=".*\.jar" />
  • 在updateHandler之前添加如下配置:
<requestHandler name="/dataimport" class="org.apache.solr.handler.dataimport.DataImportHandler">
    <lst name="defaults">
      <str name="config">data-config.xml</str>
    </lst>
</requestHandler>

启动

  • 在E:\solr-6.3.0\bin目录下,启动控制台(cmd),通过命令solr start即可启动
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 3
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值