solr7.2.0定时全量和增量更新

1、创建 dataimport.properties 文件

不久前电商项目要用到solr服务,之前对solr了解未多,最近重要做了安solr,刚起用docker安装,后续感觉docker维护起来较艰难,原本一直丢弃进Tomcat就能够启动了,何必搞那么烦。废话不多,记录下今天缓解眼前风行版本6.5.1之定时增量更新问题

#################################################
# #
# dataimport scheduler properties #
# #
#################################################

1.依赖jar包

官给的jar比较老矣,新本子的实例化更新了办法,这个jar的源码也需要创新了,主要调整措施要参照了博客:http://blog.csdn.net/yxue1118/article/details/51800145
自再也改的jar包在这个下载:
http://download.csdn.net/detail/a1556274485/9860262

# to sync or not to sync
# 1 – active; anything else – inactive
# \u8FD9\u91CC\u7684\u914D\u7F6E\u4E0D\u7528\u4FEE\u6539
syncEnabled=1

2.布局文件

在solr_home下新建conf文件夹,将dataimport.properties放在该目录下
dataimport.properties内容如下:

# dataimport.properties example
#
# From this example, copy everything bellow "dataimport scheduler properties" to your
#   dataimport.properties file and then change params to fit your needs
#
# IMPORTANT:
# Regardless of whether you have single or multiple-core Solr,
#   use dataimport.properties located in your solr.home/conf (NOT solr.home/core/conf)
# For more info and context see here:
# http://wiki.apache.org/solr/DataImportHandler#dataimport.properties_example


#Tue Jul 21 12:10:50 CEST 2010
metadataObject.last_index_time=2010-09-20 11\:12\:47
last_index_time=2010-09-20 11\:12\:47


#################################################
#                                               #
#       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=solr-test

#  solr server name or IP address
#  [defaults to localhost if empty]
server=localhost

#  solr server port
#  [defaults to 80 if empty]
port=8080

#  application name/context
#  [defaults to current ServletContextListener's context (app) name]
webapp=solr

#  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=data&verbose=false&debug=false

#  schedule interval
#  number of minutes between two runs
#  [defaults to 30 if empty]
interval=10

# 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
#
\u4FEE\u6539\u6210\u4F60\u6240\u4F7F\u7528\u7684core\uFF0C\u6211\u8FD9\u91CC\u662F\u6211\u81EA\u5B9A\u4E49\u7684core\uFF1Asimple
syncCores=xt_pdd

3.web.xml多监听

以以下代码添加进web.xml:

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

# solr server name or IP address
# [defaults to localhost if empty]
#\u8FD9\u4E2A\u4E00\u822C\u90FD\u662Flocalhost\u4E0D\u4F1A\u53D8
server=localhost

4.再开solr项目,查看日志情况,若日志输出正常,则配备是

# solr server port
# [defaults to 80 if empty]
#
\u5B89\u88C5solr\u7684tomcat\u7AEF\u53E3\uFF0C\u5982\u679C\u4F60\u4F7F\u7528\u7684\u662F\u9ED8\u8BA4\u7684\u7AEF\u53E3\uFF0C\u5C31\u4E0D\u7528\u6539\u4E86\uFF0C\u5426\u5219\u6539\u6210\u81EA\u5DF1\u7684\u7AEF\u53E3\u5C31\u597D\u4E86
port=8088

# application name/context
# [defaults to current ServletContextListener’s context (app) name]
# \u8FD9\u91CC\u9ED8\u8BA4\u4E0D\u6539
webapp=/

# URL params [mandatory]
# remainder of URL
#
\u8FD9\u91CC\u6539\u6210\u4E0B\u9762\u7684\u5F62\u5F0F\uFF0Csolr\u540C\u6B65\u6570\u636E\u65F6\u8BF7\u6C42\u7684\u94FE\u63A5
params=/dataimport?command=delta-import&clean=false&commit=true
#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]
#\u8FD9\u91CC\u662F\u8BBE\u7F6E\u5B9A\u65F6\u4EFB\u52A1\u7684\uFF0C\u5355\u4F4D\u662F\u5206\u949F\uFF0C\u4E5F\u5C31\u662F\u591A\u957F\u65F6\u95F4\u4F60\u68C0\u6D4B\u4E00\u6B21\u6570\u636E\u540C\u6B65\uFF0C\u6839\u636E\u9879\u76EE\u9700\u6C42\u4FEE\u6539
#
\u5F00\u59CB\u6D4B\u8BD5\u7684\u65F6\u5019\u4E3A\u4E86\u65B9\u4FBF\u770B\u5230\u6548\u679C\uFF0C\u65F6\u95F4\u53EF\u4EE5\u8BBE\u7F6E\u77ED\u4E00\u70B9
interval=1

#
\u91CD\u505A\u7D22\u5F15\u7684\u65F6\u95F4\u95F4\u9694\uFF0C\u5355\u4F4D\u5206\u949F\uFF0C\u9ED8\u8BA47200\uFF0C\u53735\u5929;
#
\u4E3A\u7A7A,\u4E3A0,\u6216\u8005\u6CE8\u91CA\u6389:\u8868\u793A\u6C38\u4E0D\u91CD\u505A\u7D22\u5F15
reBuildIndexInterval=7200

# \u91CD\u505A\u7D22\u5F15\u7684\u53C2\u6570
reBuildIndexParams=/select?qt=/dataimport&command=full-import&clean=true&commit=true

#
\u91CD\u505A\u7D22\u5F15\u65F6\u95F4\u95F4\u9694\u7684\u8BA1\u65F6\u5F00\u59CB\u65F6\u95F4\uFF0C\u7B2C\u4E00\u6B21\u771F\u6B63\u6267\u884C\u7684\u65F6\u95F4=reBuildIndexBeginTime+reBuildIndexInterval*60*1000\uFF1B
# \u4E24\u79CD\u683C\u5F0F\uFF1A2012-04-11 03:10:00 \u6216\u8005
03:10:00\uFF0C\u540E\u4E00\u79CD\u4F1A\u81EA\u52A8\u8865\u5168\u65E5\u671F\u90E8\u5206\u4E3A\u670D\u52A1\u542F\u52A8\u65F6\u7684\u65E5\u671F
reBuildIndexBeginTime=03:10:00

2、solr-data-import-scheduler 引入项目

百度网盘下载地址

链接:https://pan.baidu.com/s/1IqI-PwLqCofIiWxUsGU\_tQ 密码:h8so

3、配置web.xml监听

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

 

发表评论

电子邮件地址不会被公开。 必填项已用*标注

网站地图xml地图