最近在做一个solr的全文检索,但是由于不想每次都是手动的去做更新操作,所以网上百度了很多。几乎都已经失效了。最后终于找到了自己想要的,然后根据自己的理解做了这个笔记,希望对大家有用。
首先
我的solr服务器是独立的那种。
进入正题
- 第一步
下载定时的jar包:一定要下载我的这个jar,好多人的jar包是没有维护过的,启动可能会报空指针或者503、方法未找到等错误(没有币可以去某宝找)
solr-dataimport-scheduler(solr7.7).jar - 第二步
下载的jar包放进服务器的WEB-INF的lib下:具体如下
文件目录:solr-7.7.2\server\solr-webapp\webapp\WEB-INF\lib
- 第三步
在WEB-INF的web.xml配置文件中添加监听(注意:这个标签是跟servlet标签同级,并且在servlet标签之前,懂的都懂)
<listener>
<listener-class>
org.apache.solr.handler.dataimport.scheduler.ApplicationListener
</listener-class>
</listener>
4.第四步
在solr文件夹下创建一个conf文件夹,与core平级,如下图
5.第五步
进入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=dbmovie,dbmtype,dbperson
# solr server name or IP address
# [defaults to localhost if empty]
#访问ip
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
#增量更新的url参数
params=/dataimport?command=delta-import&clean=false&commit=true
#增量更新的时间间隔,分钟数,为空则默认30分钟
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
然后启动命令,可以省略 start
solr -f
参数 -f 表示前台启动,可以看到打印的log日志,关闭窗口就代表关闭服务
6.结果
如果启动时报空指针异常,可能是dataimport.properties配置文件不对,检查下路径,也有人说应该放在solr文件夹下solr.xml文件中配置的home路径下,但是我去看了这个xml,没有这个home路径
所以我就直接把properties文件放在了 第4步 的 conf 文件夹下
最后成功的样子,控制台可以看到每隔一分钟就会有增量索引的查询
如果本文中有错误的地方,尽管批评指正。