码迷,mamicode.com
首页 > 其他好文 > 详细

solr dataimport

时间:2014-07-09 19:14:46      阅读:266      评论:0      收藏:0      [点我收藏+]

标签:des   style   blog   http   color   文件   

solrconfig.xml

bubuko.com,布布扣
    <requestHandler name="/dataimport" class="org.apache.solr.handler.dataimport.DataImportHandler">
        <lst name="defaults">
          <str name="config">data-config.xml</str>
          <str name="df">text</str>
        </lst>
    </requestHandler>
View Code

 

solrconfig.xml同一个目录下增加 data-config.xml 文件

bubuko.com,布布扣
<dataConfig>
    <dataSource type="JdbcDataSource" name="ds-1" 
            driver="com.microsoft.sqlserver.jdbc.SQLServerDriver"
            url="jdbc:sqlserver://localhost;databaseName=My_DB;responseBuffering=adaptive;"
            user="you name" 
            password="you password"/>  
    <dataSource type="JdbcDataSource" name="ds-2" 
            driver="com.mysql.jdbc.Driver" 
            url="jdbc:mysql://db2-host/dbname" 
            user="db_username" 
            password="db_password"/> 
    <dataSource type="FileDataSource" name="ds-3" encoding="UTF-8" />
              
  <document>
    <!--add filed for match sql column to solr column-->
    <entity name="product" dataSource="ds-1"  
        query="select top 1 * from Product"
        transformer="RegexTransformer,DateFormatTransformer" >  
        <field column="Id" name="id"/>        
        <entity name="productCategory" dataSource="ds-1"  
            query="select top 1 * from Code_Category_Product 
                Where Id=${product.CategoryId}">
            <field column="Id" name="categoryid"/>
            <field column="Description" name="category"/>
        </entity>
        <field column="Name" name="name" />
        <field column="Description" name="description" />
        <field column="UnitPrice" name="unitprice"/>
        <field column="Status" name="status"/>
        <field column="CreatedTime" name="createdtime" dateTimeFormat="M/d/yyyy h:m:s a"/>
        <field column="Name" regex=".*Product1" name="name_py" />
    </entity>
    
    <!--atch sql column to solr column in the sql query-->
    <entity name="product2" dataSource="ds-1"  
        query="select Id as id,
                CategoryId,
                Name as name, 
                Description as description,
                UnitPrice as unitprice,
                Status as status,
                CreatedTime as createdTime from Product
                Where Id=10000000002">    
        <entity name="productCategory" dataSource="ds-1"  
            query="select top 1 * from Code_Category_Product 
                Where Id=${product2.CategoryId}">
            <field column="Id" name="categoryid"/>
            <field column="Description" name="category"/>            
        </entity>
    </entity>
    
    <entity name="product3" dataSource="ds-3"  
        processor="XPathEntityProcessor"  
        stream="true"  
        forEach="/products/product | /products/item"  
        url="D:\Solr\solr-NewRMS\example\conf\products.xml"
        transformer="RegexTransformer,DateFormatTransformer" >  
            <field column="id" xpath="/products/product/id" />  
            <field column="name" xpath="/products/product/@name" />  
            <field column="name_py" xpath="/products/product/name_py" />  
            <field column="createdtime" xpath="/products/product/createdtime" dateTimeFormat="yyyy-MM-dd‘T‘hh:mm:ss‘Z‘" />  
            <field column="tag" xpath="/products/product/tag" splitBy=","/>
            <field column="description" regex="/products/product/description" />
       </entity>  

  </document>
</dataConfig>
View Code

 

data-config.xml同一个目录下增加 products.xml

bubuko.com,布布扣
<products>
    <product name="product1001">
        <id>1001</id>
        <createdtime>2011-11-07T17:05:14</createdtime>
        <description><![CDATA[this is 1001 desc]]></description>
        <tag>tag11,tag22</tag>
    </product>
    <product name="product1002">
        <id>1002</id>
        <name_py></name_py>
        <createdtime>2012-11-07T17:05:14</createdtime>
        <description><![CDATA[this is 1002 description]]></description>
        <tag>tag1</tag>
        <tag>tag2</tag>
    </product>
</products>
View Code

 

数据库:Product 

bubuko.com,布布扣

bubuko.com,布布扣

 

 如果不想把之前的数据清除 取消 Clean 选项
 在Entity中选择运行项
 点击Execute, 一段时间后点击Refresh Status查看运行结果
 可以去Query中查看是否已经插入数据

bubuko.com,布布扣

 

 

 

 

solr dataimport,布布扣,bubuko.com

solr dataimport

标签:des   style   blog   http   color   文件   

原文地址:http://www.cnblogs.com/dfg727/p/3831631.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!