Solr增量索引

注:全量索引和增量索引data-config.xml和delta-data-config.xml配置文件默认放在和solrconfig.xml同级目录

solrconfig.xml配置如下:

[java]  view plain  copy
  在CODE上查看代码片 派生到我的代码片
  1. <requestHandler name="/dataimport"  
  2.          class="org.apache.solr.handler.dataimport.DataImportHandler">  
  3.          <lst name="defaults">  
  4.               <str name="config">delta-data-config.xml</str>  
  5.          </lst>  
  6.     </requestHandler>  


delta-data-config.xml


[java]  view plain  copy
  在CODE上查看代码片 派生到我的代码片
  1.  <dataConfig>  
  2.     <dataSource name="jdbc" driver="com.mysql.jdbc.Driver"  
  3.         url="jdbc:mysql://localhost:3306/test?zeroDateTimeBehavior=convertToNull"  
  4.         user="root" password="shyh"/>  
  5.     <document name="st_data">  
  6.         <entity name="solrtext" pk="id"  
  7.                query="select * from solrtext"  
  8.                 deltaImportQuery="select * from solrtext where id='${dih.delta.id}'"  
  9.                 deltaQuery="select id from solrtext where addon > '${dih.last_index_time}'"  
  10.                 transformer="RegexTransformer">  
  11.             <field column="id" name="id" />  
  12.             <field column="url" name="url" />  
  13.             <field column="title" name="title" />  
  14.             <field column="author" name="author" />  
  15.         <field column="addon" name="addon"/>  
  16.         <field column="path" name="path"/>  
  17.         </entity>  
  18.     </document>  
  19. </dataConfig>  


schemal.xml

[java]  view plain  copy
  在CODE上查看代码片 派生到我的代码片
  1. <field name="id" type="string" indexed="true" stored="true" required="true" multiValued="false" />   
  2. <field name="url" type="text_general" indexed="true" stored="true" />  
  3. <field name="title" type="text_general" indexed="true" stored="true"/>  
  4. <field name="author" type="text_general" indexed="true" stored="true"/>  
  5. <field name="addon" type="string" indexed="true" stored="true"/>  
  6.  <field name="path" type="string" indexed="false" stored="true"/>  

上面主要是通过内置变量“${dih.delta.id}”和 “${dih.last_index_time}”来记录本次索引的id和最后索引时间。这里,会保存在deltaimport.properties文件中,示例如下:

[java]  view plain  copy
  在CODE上查看代码片 派生到我的代码片
  1. #Mon Jan 26 11:13:07 CST 2015  
  2. solrtext.last_index_time=2015-01-26 11\:12\:35  
  3. last_index_time=2015-01-26 11\:12\:35  


配置定时任务:

  • 将 apache-solr-dataimportscheduler-1.0.jar 和solr自带的 apache-solr-dataimporthandler-.jar, apache-solr-dataimporthandler-extras-.jar 放到tomcat/webapps/solr/WEB-INF的lib目录下面 
  • 修改solr中WEB-INF/web.xml
  • [java]  view plain  copy
      在CODE上查看代码片 派生到我的代码片
    1. <listener>  
    2.           <listener-class>  
    3.                 org.apache.solr.handler.dataimport.scheduler.ApplicationListener  
    4.           </listener-class>  
    5. </listener>  

    将apache-solr-dataimportscheduler-.jar 中 dataimport.properties 取出并根据实际情况修改,然后放到 solr.home/conf (不是solr.home/core/conf) 目录下面 ,我的位置为:F:\solr\solrhome\conf(如不存在conf可手动新建,dataimport.properties存放在tomcat的solr.xml里配置的solr/home路径的conf文件夹下
  • solr.xml配置如下
  • [java]  view plain  copy
      在CODE上查看代码片 派生到我的代码片
    1. <?xml version="1.0" encoding="UTF-8" standalone="yes"?>  
    2.    <Context docBase="F:\solr\apache-tomcat-7.0.53\webapps\solr.war" debug="0" crossContext="true" >  
    3.     <Environment name="solr/home" type="java.lang.String" value="F:\solr\solrhome" override="true" />  
    4.    </Context>  


  • dataimport.properties配置说明
  • [java]  view plain  copy
      在CODE上查看代码片 派生到我的代码片
    1. #################################################  
    2. #                                               #  
    3. #       dataimport scheduler properties         #  
    4. #                                               #  
    5. #################################################  
    6.    
    7. #  to sync or not to sync  
    8. #  1 - active; anything else - inactive  
    9. syncEnabled=1  
    10.    
    11. #  which cores to schedule  
    12. #  in a multi-core environment you can decide which cores you want syncronized  
    13. #  leave empty or comment it out if using single-core deployment  
    14. syncCores=collection1  
    15.    
    16. #  solr server name or IP address  
    17. #  [defaults to localhost if empty]  
    18. server=localhost  
    19.    
    20. #  solr server port  
    21. #  [defaults to 80 if empty]  
    22. port=8080  
    23.    
    24. #  application name/context  
    25. #  [defaults to current ServletContextListener's context (app) name]  
    26. webapp=solr  
    27.    
    28. #  URL params [mandatory]  
    29. #  remainder of URL  
    30. params=/dataimport?command=delta-import&clean=false&commit=true  
    31.    
    32. #  schedule interval  
    33. #  number of minutes between two runs  
    34. #  [defaults to 30 if empty]  
    35. interval=1  
    36.    
    37. #  重做索引的时间间隔,单位分钟,默认7200,即5天;   
    38. #  为空,为0,或者注释掉:表示永不重做索引  
    39. reBuildIndexInterval=7200  
    40.    
    41. #  重做索引的参数  
    42. reBuildIndexParams=/dataimport?command=full-import&clean=true&commit=true  
    43.    
    44. #  重做索引时间间隔的计时开始时间,第一次真正执行的时间=reBuildIndexBeginTime+reBuildIndexInterval*60*1000;  
    45. #  两种格式:2012-04-11 03:10:00 或者  03:10:00,后一种会自动补全日期部分为服务启动时的日期  
    46. reBuildIndexBeginTime=03:10:00  





  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值