zoukankan      html  css  js  c++  java
  • 如何将数据库中的数据导入到Solr中

    要使用solr实现网站中商品搜索,需要将mysql数据库中数据在solr中创建索引.

    1.需要在solr的schema.xml文件定义要存储的商品Field.

    商品表中的字段为:

    配置内容是:

    <!--product-->
    <field name="product_name" type="text_ik" indexed="true" stored="true"/>
    <field name="product_price"  type="float" 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_catalog_name" type="string" indexed="true" 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"/>

     然后将数据库中的数据导入到solr中:

    需要将

     这个三个jar包导入到lib下.这三个jar包分别dataimportHandler插件.和mysql数据库的数据库驱动

    将数据库中

    改成%,才能.

    配置solrconfig.xml文件,添加一个requestHhander.

     <requestHandler name="/dataimport" 
    class="org.apache.solr.handler.dataimport.DataImportHandler">
        <lst name="defaults">
          <str name="config">data-config.xml</str>
         </lst>
      </requestHandler> 

    第三步:创建一个data-config.xml,保存到coolection1conf目录下

    <?xml version="1.0" encoding="UTF-8" ?>  
    <dataConfig>   
    <dataSource type="JdbcDataSource"   
              driver="com.mysql.jdbc.Driver"   
              url="jdbc:mysql://localhost:3306/lucene"   
              user="root"   
              password="root"/>   
    <document>   
        <entity name="product" query="SELECT pid,name,catalog_name,price,description,picture FROM products ">
             <field column="pid" name="id"/> 
             <field column="name" name="product_name"/> 
             <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>

    这里需要修改ip地址和数据库名字

    我这里使用ip为192.168.200.1,因为我是在虚拟机中安装的这个软件.

    最后就是需要重启tomcat,还有就是mysql的服务,也需要重新启动.

  • 相关阅读:
    网络编程2018-4-23
    网络编程
    异常处理
    在Asp.net core使用配置Json创建动态目录树
    Asp.net Core中文转换成拼音
    解决Asp.Net core 控制台出现乱码的情况
    解决Asp.net Core中chtml文档中文乱码的问题
    取代Ajax.BeginForm的ajax使用方法
    将数据库模型放入到.Net Core的类库中
    如何使用Resource资源文件
  • 原文地址:https://www.cnblogs.com/qingmuchuanqi48/p/10734116.html
Copyright © 2011-2022 走看看