1128XF

Solr定时导入功能实现

需要实现Solr定时导入功能的话,我们可以通过使用Solr自身所集成的dataimportscheduler调度器实现

 

下载对应的jar包,下载地址https://code.google.com/archive/p/solr-dataimport-scheduler/downloads

 

 

 

通过WinRAR打开jar包我们发现里面有一个名叫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=game,resource

#  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

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

#  重做索引的时间间隔,单位分钟,默认7200,即1天; 
#  为空,为0,或者注释掉:表示永不重做索引
reBuildIndexInterval=2

#  重做索引的参数
reBuildIndexParams=/select?qt=/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
定时导入功能,则是根据该配置文件的所配置的数据进行实现
   第一步,将所下载的jar包,添加到WEB-INF\lib目录下

  第二步,在项目的web.xml配置文件中添加监听配置
<listener>    
    <listener-class>    
            org.apache.solr.handler.dataimport.scheduler.ApplicationListener    
    </listener-class>    
  </listener> 

 

 第三步、在solrhome目录下,新建conf文件夹,并将dataimport.properties文件添加进入,修改其中的配置参数

第四步、也是最重要的一步,修改data-config.xml配置文件,在entity中还有两个属性deltaImportQuery与deltaQuery,其实这里又额外涉及到另外三个参数,
    第一个是数据库中记录数据录入的时间字段updatetime,
    第二个则是前面所提到每个索引库自身的导入时间,在dataimport.properties中会自动生成
    第三个是主键id
在这张图中可以展现各参数的作用点

 

 在所有配置完成之后,接下来就是测试阶段,查看服务器是否会自动更新索引库数据

 

 

posted on 2017-02-26 16:48  1128XF  阅读(700)  评论(0编辑  收藏  举报

导航