solr自动增量更新

1.导入增量更新罐包

将阿帕奇的Solr中的-dataimportscheduler.src.jar复制到solr的中的lib目录下

2.配置增量文件更新
在solr_home目录下新建一个文件夹conf,再在conf文件夹下

新建dataimport.properties文件,其内容为

#################################################  
#                                               #  
#       dataimport scheduler properties         #  
#                                               #  
#################################################  
		   
#  to sync or not to sync  
#  1 - active; anything else - inactive  
syncEnabled=1
#  which cores to schedule  
#  in a multi-core environment you can decide which cores you want syncronized  
#  leave empty or comment it out if using single-core deployment  
syncCores=test,hotel
#  solr server name or IP address  
#  [defaults to localhost if empty]  
server=localhost
#  solr server port  
#  [defaults to 80 if empty]  
port=8083
#  application name/context  
#  [defaults to current ServletContextListener's context (app) name]  
webapp=solr
#  增量索引的参数   
#  URL params [mandatory]  
#  remainder of URL  
params=/dataimport?command=delta-import&clean=false&commit=true
#  重做增量索引的时间间隔  
#  schedule interval  
#  number of minutes between two runs  
#  [defaults to 30 if empty]  
interval=1
#  重做全量索引的时间间隔,单位分钟,默认7200,即5天;  
#  为空,为0,或者注释掉:表示永不重做索引  
#reBuildIndexInterval=7200
#  重做索引的参数  
reBuildIndexParams=/dataimport?command=full-import&clean=true&commit=true
#  重做索引时间间隔的计时开始时间,第一次真正执行的时间=reBuildIndexBeginTime+reBuildIndexInterval*60*1000;  
#  两种格式:2012-04-11 03:10:00 或者  03:10:00,后一种会自动补全日期部分为服务启动时的日期  
reBuildIndexBeginTime=03:10:00

3.增加增量更新监听器

在Solr的中的web.xml文件中加入

<listener>
    <listener-class>
	org.apache.solr.handler.dataimport.scheduler.ApplicationListener
    </listener-class>
</listener>

4.编写增量更新SQL

在d:\ solr_home \酒店\ CONF \数据-config.xml中中的<实体>标签加入两个属性

<?xml version="1.0" encoding="utf-8"?>
<dataConfig>
	<dataSource type="JdbcDataSource" driver="com.mysql.jdbc.Driver" url="jdbc:mysql://192.168.126.133:3306/itripdb" user="root" password="123456"/>
	<document name="hotel_doc">
	<entity name="hotel" pk="id" 
            query="select id, hotelName, address from itrip_hotel"  deltaImportQuery="select id, hotelName, address from itrip_hotel where id = '${dih.delta.id}'"
deltaQuery="select id as id from itrip_hotel where modifyDate > '${dih.last_index_time}'">
            <field column="id" name="id"/>
            <field column="hotelName" name="hotelName"/>
            <field column="address" name="address"/>
        </entity>
    </document>
</dataConfig>

PS:字段被修改的时间一定要晚于数据导入到Solr中的时间,我在这里就犯了错误,铭记铭记

ps: 加入监听器之后,项目出现404,原因是监听器标签前有bom识别符,去掉之后就可以了。

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值