if (mIndexSearcher != null) {
try {
mIndexSearcher.close();
}
catch (IOException exc) {
throw new RegainException("Closing index searcher failed", exc);
}
// Force the creation of a new IndexSearcher and Analyzer next time it
// will be needed
mIndexSearcher = null;
mAnalyzer = null;
}
// Close the IndexReader
if (mIndexReader != null) {
try {
mIndexReader.close();
}
catch (IOException exc) {
throw new RegainException("Closing index reader failed", exc);
}
// Force the creation of a new IndexReader and mFieldTermHash next time
// it will be needed
mIndexReader = null;
mFieldTermHash = null;
}
// Remove the old backup if it should still exist
if (mBackupIndexDir.exists()) {
RegainToolkit.deleteDirectory(mBackupIndexDir);
}
// Backup the current index (if there is one)
if (mWorkingIndexDir.exists()) {
if (! mWorkingIndexDir.renameTo(mBackupIndexDir)) {
throw new RegainException("Renaming " + mWorkingIndexDir + " to "
+ mBackupIndexDir + " failed!");
}
}
// Move the new index
if (! mNewIndexDir.renameTo(mWorkingIndexDir)) {
throw new RegainException("Renaming " + mNewIndexDir + " to "
+ mWorkingIndexDir + " failed!");
}
}
}