Package com.gentics.cr.lucene.indexer.index

Source Code of com.gentics.cr.lucene.indexer.index.CRLuceneOptimizeJob

package com.gentics.cr.lucene.indexer.index;

import java.io.IOException;
import java.util.concurrent.ConcurrentHashMap;

import org.apache.log4j.Logger;
import org.apache.lucene.index.IndexWriter;

import com.gentics.cr.CRConfig;
import com.gentics.cr.CRConfigUtil;
import com.gentics.cr.exceptions.CRException;
import com.gentics.cr.lucene.indexaccessor.IndexAccessor;
import com.gentics.cr.util.indexing.AbstractUpdateCheckerJob;
import com.gentics.cr.util.indexing.IndexLocation;

public class CRLuceneOptimizeJob extends AbstractUpdateCheckerJob {

  public CRLuceneOptimizeJob(CRConfig config, IndexLocation indexLoc, ConcurrentHashMap<String, CRConfigUtil> configmap) {
    super(config, indexLoc, configmap);
    log = Logger.getLogger(CRLuceneOptimizeJob.class);
    // TODO Auto-generated constructor stub
  }

  @Override
  protected final void indexCR(final IndexLocation indexLocation, final CRConfigUtil config) throws CRException {
    if (indexLocation instanceof LuceneIndexLocation) {
      log.debug("Starting to optimize index.");
      LuceneIndexLocation luceneIndexLoccation = (LuceneIndexLocation) indexLocation;
      IndexAccessor ia = luceneIndexLoccation.getAccessor();
      IndexWriter writer = null;
      try {
        writer = ia.getWriter();
        writer.optimize();
      } catch (IOException e) {
        log.error("Optimize index.", e);
      } finally {
        ia.release(writer);
      }
      log.debug("Finished optimizing index.");
    } else {
      log.error("Index does not seem to be a Lucene index. Therfore no " + "optimizing will be done.");
    }
  }

}
TOP

Related Classes of com.gentics.cr.lucene.indexer.index.CRLuceneOptimizeJob

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.