Package com.jalios.jcms.search
Class LuceneUtils
java.lang.Object
com.jalios.jcms.search.LuceneUtils
Provide misc utility when working with lucene
- Since:
- jcms-8.0.0
-
Nested Class Summary
Nested Classes -
Method Summary
Modifier and TypeMethodDescriptionstatic booleanChecks whether the given directory contains a Lucene index written with a version that is no longer supported by the current Lucene runtime.static org.apache.lucene.store.FSDirectoryopenAndCheckDirectory(org.apache.log4j.Logger logger, File dir) Open the FSDirectory corresponding to the specified directory.static org.apache.lucene.store.FSDirectoryopenAndCheckDirectory(org.apache.log4j.Logger logger, File dir, Runnable onRecovery) Open the FSDirectory corresponding to the specified directory.static voidwriteErrorWitnessFile(File witnessFile, Exception ex) Write the specified exception to the specified witness file
-
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: truewas 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 messagesdir- the filesystem directory that should contain the lucene index- Returns:
- a instance of FSDirectory opened and ready for use, never return null
- Throws:
IOExceptionException- Since:
- 10.0.8 / JCMS-10640
- deletes any existing lock when
-
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: truewas 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 messagesdir- the filesystem directory that should contain the lucene indexonRecovery- 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
- deletes any existing lock when
-
isOldUnsupportedIndex
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
Write the specified exception to the specified witness file- Parameters:
witnessFile- a File to which write the exceptionex- the exception to write- Since:
- 10.0.8 / JCMS-10258
-