Class LuceneUtils

java.lang.Object
com.jalios.jcms.search.LuceneUtils

public abstract class LuceneUtils extends Object
Provide misc utility when working with lucene
Since:
jcms-8.0.0
  • Method Details

    • openAndCheckDirectory

      public static org.apache.lucene.store.FSDirectory openAndCheckDirectory(org.apache.log4j.Logger logger, File dir) throws Exception
      Open the FSDirectory corresponding to the specified directory. This method :
      • deletes any existing lock when search-engine.simple-fs-lock: true was configured.
      • creates a new index if required
      • or check integrity of an existing index if any. If an exception occurs during this verification, and self recovery is enabled (search-engine.self-recovery: true), this method attempts to rename the existing engine directory to a backup folder using the current date, and attempt the creation of a new empty index.
      Parameters:
      logger - the Logger to use to print info/warn messages
      dir - the filesystem directory that should contain the lucene index
      Returns:
      a instance of FSDirectory opened and ready for use, never return null
      Throws:
      IOException
      Exception
      Since:
      10.0.8 / JCMS-10640
    • openAndCheckDirectory

      public static org.apache.lucene.store.FSDirectory openAndCheckDirectory(org.apache.log4j.Logger logger, File dir, Runnable onRecovery) throws IOException
      Open the FSDirectory corresponding to the specified directory. This method :
      • deletes any existing lock when search-engine.simple-fs-lock: true was configured.
      • creates a new index if required
      • or check integrity of an existing index if any. If an exception occurs during this verification, and self recovery is enabled (search-engine.self-recovery: true), this method attempts to rename the existing engine directory to a backup folder using the current date, and attempt the creation of a new empty index.
      Parameters:
      logger - the Logger to use to print info/warn messages
      dir - the filesystem directory that should contain the lucene index
      onRecovery - optional callback invoked if the existing index could not be loaded and a new empty one was created successfully
      Returns:
      a instance of FSDirectory opened and ready for use, never return null
      Throws:
      IOException
      Since:
      11.0.0 / JCMS-11817
    • isOldUnsupportedIndex

      public static boolean isOldUnsupportedIndex(File dir)
      Checks whether the given directory contains a Lucene index written with a version that is no longer supported by the current Lucene runtime.
      Parameters:
      dir - the index directory to check
      Returns:
      true if the directory contains an outdated Lucene index, false otherwise
      Since:
      11.0.0 - JCMS-11802
    • writeErrorWitnessFile

      public static void writeErrorWitnessFile(File witnessFile, Exception ex)
      Write the specified exception to the specified witness file
      Parameters:
      witnessFile - a File to which write the exception
      ex - the exception to write
      Since:
      10.0.8 / JCMS-10258