solr6.6定时实时重建索引和增量更新

来源:互联网 发布:易语言电视直播源码 编辑:程序博客网 时间:2024/06/05 02:24

    1. 将 apache-solr-dataimportscheduler-1.1.jar 和solr自带的 apache-solr-dataimporthandler-5.1.0.jar, apache-solr-dataimporthandler-extras-5.1.0.jar 放到 tomcat/webapps/solr/WEB-INF/lib/ 目录下面

    2.修改tomcat/webapps/solr/WEB-INF/中的web.xml, 在servlet节点前面增加:

[html] view plain copy
  1. <listener>  
  2.     <listener-class>org.apache.solr.handler.dataimport.scheduler.ApplicationListener</listener-class>  
  3. </listener>  

    3.将apache-solr-dataimportscheduler-1.1.jar 中 dataimport.properties 取出并根据实际情况修改,然后放到 solr_home/conf (不是solr_home/core1/conf) 目录下面,solr_home/conf文件夹没有的话手动创建


    4.重启tomcat

dataimport.properties 配置项修改说明:

  1. #################################################  
  2. #                                               #  
  3. #       dataimport scheduler properties         #  
  4. #                                               #  
  5. #################################################  
  6.   
  7. #  to sync or not to sync  
  8. #  1 - active; anything else - inactive  
  9. syncEnabled=1  
  10.   
  11. #  which cores to schedule  
  12. #  in a multi-core environment you can decide which cores you want syncronized  
  13. #  leave empty or comment it out if using single-core deployment  
  14. syncCores=core1  
  15.   
  16. #  solr server name or IP address  
  17. #  [defaults to localhost if empty]  
  18. server=localhost  
  19.   
  20. #  solr server port  
  21. #  [defaults to 80 if empty]  
  22. port=8080  
  23.   
  24. #  application name/context  
  25. #  [defaults to current ServletContextListener's context (app) name]  
  26. webapp=solr  
  27.   
  28. #  URL params [mandatory]  
  29. #  remainder of URL  
  30. #增量  
  31. params=/dataimport?command=delta-import&clean=false&commit=true&optimize=false&wt=json&indent=true&entity=students&verbose=false&debug=false  
  32.   
  33. #  schedule interval  
  34. #  number of minutes between two runs  
  35. #  [defaults to 30 if empty]  
  36. interval=20  
  37.   
  38. #  重做索引的时间间隔,单位分钟,默认7200,即1天;   
  39. #  为空,为0,或者注释掉:表示永不重做索引  
  40. reBuildIndexInterval=7200  
  41.   
  42. #  重做索引的参数  
  43. reBuildIndexParams=/dataimport?command=full-import&clean=true&commit=true&optimize=true&wt=json&indent=true&entity=students&verbose=false&debug=false  
  44.   
  45. #  重做索引时间间隔的计时开始时间,第一次真正执行的时间=reBuildIndexBeginTime+reBuildIndexInterval*60*1000;  
  46. #  两种格式:2012-04-11 03:10:00 或者  03:10:00,后一种会自动补全日期部分为服务启动时的日期  
  47. reBuildIndexBeginTime=09:00:00  
到这里就完了,如果你启动就会报一个找不到方法的错误:


为什么会爆这个错,因为SolrDataImportProperties类的loadProperties方法里面:



SolrResourceLoader是solr里面的核心方法,这里传了一个null,但是后面有调用了一个方法,但是我看源码发现没有这个方法,应该是新的版本改了;



上面我做了一点改动,调用无参的构造方法,重新编译打包jar,之后就可以完美运行了;

jar:https://pan.baidu.com/s/1o8jxn8u

源码:https://pan.baidu.com/s/1kUGxnld