solr定时增量更新需要再添加一个jar包。solr4、solr5、solr6由于solr-core-x.jar的源码的调整,不能使用同一个jar包。solr4由于版本过老就暂时不做介绍,solr5所需jar包下载、源码下载,solr6所需jar包下载、源码下载。solr5与6设置定时增量更新步骤相同,只是所需的该jar包不同。
1、将 apache-solr-dataimportscheduler-1.0.jar 和solr自带的 apache-solr-dataimporthandler-.jar, apache-solr-dataimporthandler-extras-.jar 放到solr的lib目录下面
2、修改solr中WEB-INF/web.xml, 在servlet节点前面增加:
<listener>
<listener-class>
org.apache.solr.handler.dataimport.scheduler.ApplicationListener
</listener-class>
</listener>
3、将apache-solr-dataimportscheduler-.jar 中 dataimport.properties 取出
将dataimport.properties下载并该文件并根据实际情况修改,然后放到 solr.home/conf (不是solr.home/core/conf) 目录下面,该目录是没有的,需要新建
4、重启tomcat,向数据库添加一条记录。注意:由于在conf下data-config.xml文件中内容如下:
<?xml version="1.0" encoding="UTF-8"?>
<dataConfig>
<dataSource name="source1" type="JdbcDataSource" driver="com.mysql.jdbc.Driver" url="jdbc:mysql://localhost:3306/zhsoftbank" user="root" password="root" batchSize="-1" />
<span style="white-space:pre"> </span><document>
<span style="white-space:pre"> </span><entity name="news" pk="id" dataSource="source1"
query="select * from news"
deltaImportQuery="select * from news where id='${dih.delta.id}'"
deltaQuery="select id from news where updateTime> '${dataimporter.last_index_time}'">
<field column="id" name="id"/>
<field column="title" name="title"/>
<field column="synopsis" name="synopsis"/>
<field column="updateTime" name="updateTime"/>
</entity>
</document>
</dataConfig>
可以看出是根据updateTime时间来增量更新索引的,所以新数据的updateTime要大于apache-tomcat-8.0.9\webapps\solr\solrhome\myindex\conf目录下dataimport.properties文件中的last_index_time的时间值。