mQuarantineIndexDir = new File(indexDir, QUARANTINE_INDEX_SUBDIR);
mTempIndexDir = new File(indexDir, TEMP_INDEX_SUBDIR);
try {
mLuceneTempIndexDir = FSDirectory.open(mTempIndexDir);
} catch (IOException ioEx) {
throw new RegainException("Couldn't open tmpIndexDir", ioEx);
}
mBreakpointIndexDir = new File(indexDir, BREAKPOINT_INDEX_SUBDIR);
mErrorLogFile = new File(mTempIndexDir, "log/error.log");
// Delete the old temp index directory if it should still exist
if (mTempIndexDir.exists()) {
RegainToolkit.deleteDirectory(mTempIndexDir);
}
// and create a new, empty one
if (!mTempIndexDir.mkdir()) {
throw new RegainException("Creating working directory failed: " + mTempIndexDir.getAbsolutePath());
}
// Get the untokenized field names
String[] untokenizedFieldNames = config.getUntokenizedFieldNames();
// Create the Analyzer
// NOTE: Make shure you use the same Analyzer in the SearchContext too!
String analyzerType = config.getAnalyzerType();
String[] stopWordList = config.getStopWordList();
String[] exclusionList = config.getExclusionList();
mAnalyzer = RegainToolkit.createAnalyzer(analyzerType, stopWordList,
exclusionList, untokenizedFieldNames);
// Alten Index kopieren, wenn Index aktualisiert werden soll
if (updateIndex) {
if (!copyExistingIndex(indexDir, analyzerType)) {
mUpdateIndex = updateIndex = false;
}
}
// Check whether we have to create a new index
boolean createNewIndex = !updateIndex;
if (createNewIndex) {
// Create a new index
try {
mIndexWriter = createIndexWriter(true);
} catch (IOException exc) {
throw new RegainException("Creating new index failed", exc);
}
}
if (updateIndex) {
// Force an unlock of the index (we just created a copy so this is save)
setIndexMode(READING_MODE);
try {
IndexWriter.unlock(mIndexReader.directory());
mInitialDocCount = mIndexReader.numDocs();
} catch (IOException exc) {
throw new RegainException("Forcing unlock failed", exc);
}
}
// Write the stopWordList and the exclusionList in a file so it can be found
// by the search mask
RegainToolkit.writeToFile(analyzerType, new File(mTempIndexDir, "analyzerType.txt"));
RegainToolkit.writeListToFile(stopWordList, new File(mTempIndexDir, "stopWordList.txt"));
RegainToolkit.writeListToFile(exclusionList, new File(mTempIndexDir, "exclusionList.txt"));
if (untokenizedFieldNames.length != 0) {
RegainToolkit.writeListToFile(untokenizedFieldNames, new File(mTempIndexDir, "untokenizedFieldNames.txt"));
}
// Prepare the analysis directory if wanted
if (config.getWriteAnalysisFiles()) {
mAnalysisDir = new File(mTempIndexDir.getAbsolutePath() + File.separator + "analysis");
if (!mAnalysisDir.mkdir()) {
throw new RegainException("Creating analysis directory failed: " + mAnalysisDir.getAbsolutePath());
}
}
mDocumentFactory = new DocumentFactory(config, mAnalysisDir);
}