Windows系统环境下Solr之Java实战(二)配置从MySQL数据库批量导入索引

1.将D:JavaWebSolrsolr-6.2.0dist下面的solr-dataimporthandler-6.2.0.jar和solr-dataimporthandler-extras-6.2.0.jar2个包导入到

       D:JavaWebSolrsolrhome ew_corelib文件夹下面        

2.将mysql-connector-java-5.1.7-bin.jar导入到D:JavaWebSolrsolrhome ew_corelib文件夹下面

3.在D:JavaWebSolrsolrhome ew_coreconfsolrconfig.xml配置文件里面增加如下配置

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

4.在D:JavaWebSolrsolrhome ew_coreconf下面新建配置文件data-config.xml

<?xml version="1.0" encoding="UTF-8"?>  
<dataConfig>  
    <dataSource type="JdbcDataSource" 
                driver="com.mysql.jdbc.Driver" 
                url="jdbc:mysql://localhost:3306/lucene?characterEncoding=utf-8" 
                user="root" 
                password="root" 
                batchSize="-1" />  
    <document>  
    <entity name="product"  query="select pid,name,catalog,catalog_name,price,number,description,picture,release_time 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>  

5.在D:JavaWebSolrsolrhome ew_coreconfmanaged-schema配置文件里面新增如下配置

    <!--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"/>

6.创建索引

7.查询

原文地址:https://www.cnblogs.com/cnki/p/6776313.html