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
  • 相关阅读:
    linux系统根目录文件系统空间不足导致的错误
    python---对象
    公共函数
    PHP接口(interface)和抽象类(abstract)
    mysql引擎
    InstallShield自定义图片资源
    InstallShield 创建自己的Dialog
    InstallShield:自己备份
    注册表和ODBC
    IS脚本学习
  • 原文地址:https://www.cnblogs.com/miye/p/8693297.html
Copyright © 2011-2022 走看看