Solr配置從Mysql導入數據到索引庫

**1.在solr的解壓縮文件中solr-4.10.4\dist下面,找到solr-dataimporthandler-4.10.4.jar與
solr-dataimporthandler-extras-4.10.4.jar:**
這裏寫圖片描述

還有mysql的驅動的jar放在solrHome下的collection1下的lib中,沒有lib文件夾可以新建
例如我的home在: G:\solr-service\solrHome

這裏寫圖片描述

2.配置核心配置文件:在solrconfig.xml中,添加一個requestHandler

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

3.創建一個data-config.xml,保存到home路徑下的collection1下的conf下:

<?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="mysql"/>
     <document>
            <entity   name="product"  query="select              pid,name,catalog_name,price,descrition,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="descrition" name="product_descrition"/>    
        <field column="picture" name="product_picture"/> 
                </entity>              
           </document>
    </dataConfig>

4.在solr的home下的collection1下config下的schema.xml中,設置業務的field,也就是上面的映射字段的name的屬性值

  <!--product-->
      <field name="product_name" type="text_ik" indexed="true" stored="true"/>   
      <field name="product_descrition" type="text_ik" indexed="true" stored="false"/>
      <field name="product_catalog_name" type="string" indexed="true" stored="true"/>    
      <field name="product_price" type="float" indexed="true" stored="true"/>   
        <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_descrition"  dest="product_keywords"/>

重啓服務即可

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章