首页 > 编程学习 > 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识别符,去掉之后就可以了。


本文链接:https://www.ngui.cc/zz/2336536.html
Copyright © 2010-2022 ngui.cc 版权所有 |关于我们| 联系方式| 豫B2-20100000