zoukankan      html  css  js  c++  java
  • Solr:将数据库导入到索引库<五>

    将数据库导入到索引库

    准备:

      • 数据表:我的测试表:testsolr
      • mysql驱动

    配置数据导入功能:

      • 在solrconfig.xml中配置requestHandler
      • 配置数据导入插件
      • 在索引库中创建lib文件夹
      • 在solrconfig.xml中引入

    1.1 自定义索引库:testsolr 

    参考 solr的第二篇,自定义索引库  

    删除复制过来的索引库中的data文件夹:没有data文件夹 会自动创建

    schema.xml 部分配置:(参考solr:自定义索引库的中的:修改schema.xml文件)

      
       <field name="id" type="string" indexed="true" stored="true" required="true" multiValued="false" /> 
       <field name="product_name" type="text_ik" indexed="true" stored="true" />
       <field name="product_catalog" type="int" indexed="true" stored="true" />
       <field name="product_catalog_name" type="text_ik" indexed="true" stored="true" />
       <field name="product_price" type="double" indexed="true" stored="true" />
       <field name="product_description" type="text_ik" indexed="true" stored="false" />
       <field name="product_picture" type="text_ik" indexed="true" stored="true" />
    
     <uniqueKey>id</uniqueKey>
    
       <field name="product_keywords" type="text_ik" indexed="true" stored="true" multiValued="true"/>
       <copyField source="product_name" dest="product_keywords"/>
       <copyField source="product_catalog_name" dest="product_keywords"/>
       <copyField source="product_description" dest="product_keywords"/>
    
    
    
        <fieldType name="text_ik" class="solr.TextField">
          <analyzer type="index" class="org.wltea.analyzer.lucene.IKAnalyzer" />
          <analyzer type="query" class="org.wltea.analyzer.lucene.IKAnalyzer" />
        </fieldType>

     

    1.2  添加dataimporthandler jar包---额外功能—插件

      在索引库中创建lib 文件夹,存放 dataimporthandler  jar包

    1.3 在solrconfig.xml中引入jar

    <lib dir="../lib/" regex="solr-dataimporthandler-d.*.jar" />

    1.4 在solrconfig.xml文件   配置requestHandler 

    <requestHandler name="/dataimport" class="org.apache.solr.handler.dataimport.DataImportHandler">
         <lst name="defaults">
           <str name="config">db-data-config.xml</str>
         </lst>
      </requestHandler>
    db-data-config.xml是连接数据库的配置文件

    1.5 conf目录下添加db-data-config.xml

    <?xml version="1.0" encoding="UTF-8" ?>  
    <dataConfig>   
    <dataSource type="JdbcDataSource"   
              driver="com.mysql.jdbc.Driver"   
              url="jdbc:mysql://127.0.0.1:3306/test01"   
              user="root"   
              password="root"/>   
    <document>   
        <entity name="product" query="SELECT pid,name,catalog,catalog_name,price,description,picture FROM testsolr">
             <field column="pid" name="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>
    field :
    • column 数据库中的列
    • name 索引库中的对应的名字

    1.6 添加mysql驱动包到solr中

    1.7 导入数据

     

  • 相关阅读:
    ContextMenuStrip 类
    ToolStripMenuItem
    ubuntu16.04下安装cuda8.0
    插入排序
    Python *args **kw
    python面向对象编程
    0/1背包问题(回溯法)
    Python decorator装饰器
    Python 函数式编程
    分治策略(求解递归式的方法)
  • 原文地址:https://www.cnblogs.com/Cyan-W/p/10006539.html
Copyright © 2011-2022 走看看