zoukankan      html  css  js  c++  java
  • Solr5.0.0定时更新索引

    由于通过配置的方式定时更新不生效,故通过代码执行定时任务更新

    package com.thinkgem.jeesite.modules.meeting.task;
    
    import java.io.IOException;
    
    import org.apache.http.HttpStatus;
    import org.apache.http.client.methods.CloseableHttpResponse;
    import org.apache.http.client.methods.HttpGet;
    import org.apache.http.impl.client.CloseableHttpClient;
    import org.apache.http.impl.client.HttpClients;
    import org.slf4j.Logger;
    import org.slf4j.LoggerFactory;
    import org.springframework.beans.factory.annotation.Value;
    import org.springframework.context.annotation.Lazy;
    import org.springframework.scheduling.annotation.Scheduled;
    import org.springframework.stereotype.Service;
    
    
    
    /** 
    * @ClassName: SolrTask 
    * @Description: 
    * @author wd
    * @date 2018年3月23日 上午11:13:22 
    *  
    */
    @Service
    @Lazy(false)
    public class SolrTask {
    
        @Value("#{APP_PROP['solr.Core.full']}")
        private String coreUrlfull;
        
        @Value("#{APP_PROP['solr.Core.delta']}")
        private String coreUrldelta;
    
        private static final Logger LOGGER = LoggerFactory.getLogger(SolrTask.class);
    
        /**
         * 
         * 适用于修改 新增 (删除未做)
         * 每日零点
         * @throws IOException 
         */
        @Scheduled(cron = "0 0 0 * * ?")
        public void SolrTaskDelta() throws IOException {
            CloseableHttpClient httpCilent = HttpClients.createDefault();
            HttpGet httpGet = new HttpGet(coreUrldelta);
            try {
                CloseableHttpResponse response = httpCilent.execute(httpGet);
                if (response != null && response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
                    LOGGER.info("solr增量索引任务执行成功" );
                }
            } catch (IOException e) {
                LOGGER.info("solr增量索引任务执行失败");
                e.printStackTrace();
            }finally {
                httpCilent.close();
            }
        }
        
    
        /**
         * 每周一零点
         * 全量索引删除后重建
         * @throws IOException 
         * 
         */
        @Scheduled(cron = "0 0 0 ? * MON ")
        public void SolrTaskFull() throws IOException {
            CloseableHttpClient httpCilent = HttpClients.createDefault();
            HttpGet httpGet = new HttpGet(coreUrlfull);
            try {
                CloseableHttpResponse response = httpCilent.execute(httpGet);
                if (response != null && response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
                    LOGGER.info("solr重建全量索引成功" );
                }
            } catch (IOException e) {
                LOGGER.info("solr重建全量索引失败");
                e.printStackTrace();
            }finally {
                httpCilent.close();
            }
        }
    }
    #期刊索引更新测试服务器
    solr.Core.delta=http://10.1.101.134:8983/solr/PaperReview/dataimport?command=delta-import&clean=false&commit=true
    solr.Core.full=http://10.1.101.134:8983/solr/PaperReview/dataimport?command=full-import&clean=true&commit=true
  • 相关阅读:
    private key and public key
    还要谈谈Equals和GetHashcode
    B+树,聚集索引,非聚集索引(辅助索引) 之一
    由TCP的可靠性实现对比WCF中可靠性的实现(未完成)
    用TCP/IP实现自己简单的应用程序协议:最后再返回来看HTTP协议
    Socket:流,TCP连接,TCP可靠性概述
    数学归纳法与递归还有斐波那契数列(未完成)
    WCF中的REST是什么
    也谈Dependency Injection(依赖注入),依赖关系转移而不是消除(未完成)
    多线程之旅——从概念开始
  • 原文地址:https://www.cnblogs.com/miye/p/8693297.html
Copyright © 2011-2022 走看看