1、下载JAR:http : //code.google.com/p/solr-data-import-scheduler/ 添加至webapp lib目录下
2、创建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=gx_core,core_magazine
# solr server name or IP address
# [defaults to localhost if empty]
server=localhost
# solr server port
# [defaults to 80 if empty]
port=8983
# application name/context
# [defaults to current ServletContextListener's context (app) name]
webapp=solr-webapp
# URL params [mandatory]
# remainder of URL
params=/select?qt=/dataimport&command=delta-import&clean=false&commit=true
#params=/dataimport?command=delta-import&clean=false&commit=true&optimize=false&wt=json&indent=true&entity=forumTopic&verbose=false&debug=false
# schedule interval
# number of minutes between two runs
# [defaults to 30 if empty]
interval=1
3.配置web.xml监听
<listener>
<listener-class>org.apache.solr.handler.dataimport.scheduler.ApplicationListener</listener-class>
</listener>
配置完重启就可以了
Linux crontab定时任务
以Linux crontab 为例 每隔一分钟,定时Get请求方式访问URL进行增量导入
Linux终端下输入crontab -e
进入编辑模式:
*/1 * * * * /usr/bin/curl -G -d "/dataimport?command=delta-import&clean=false&commit=true" http://localhost:8983/solr/core1
然后重启服务
service crond restart //重启服务
window 使用cur命令 (cur 需要安装:https://curl.haxx.se/download.html 下载后把crul.exr拷到C盘windows system32下)
命令:(批处理下特殊符号转义加^)
curl http://localhost:8983/solr/core1/dataimport?command=delta-import^&clean=false^&commit=true
添加到定时任务即可
vbs运行不弹命令窗口
Set ws = CreateObject("Wscript.Shell")
ws.run "cmd /c solr.bat",0