use of org.apache.lucene.facet.taxonomy.SearcherTaxonomyManager in project nrtsearch by Yelp.
the class ShardState method start.
/**
* Start this shard as standalone (not primary nor replica)
*/
public synchronized void start() throws Exception {
if (isStarted()) {
throw new IllegalStateException("index \"" + name + "\" was already started");
}
try {
if (indexState.saveLoadState == null) {
indexState.initSaveLoadState();
}
Path indexDirFile;
if (rootDir == null) {
indexDirFile = null;
} else {
indexDirFile = rootDir.resolve("index");
}
origIndexDir = indexState.df.open(indexDirFile, indexState.globalState.getConfiguration().getPreloadConfig());
// nocommit remove NRTCachingDir too?
if ((origIndexDir instanceof MMapDirectory) == false) {
double maxMergeSizeMB = indexState.getDoubleSetting("nrtCachingDirectoryMaxMergeSizeMB", 5.0);
double maxSizeMB = indexState.getDoubleSetting("nrtCachingDirectoryMaxSizeMB", 60.0);
if (maxMergeSizeMB > 0 && maxSizeMB > 0) {
indexDir = new NRTCachingDirectory(origIndexDir, maxMergeSizeMB, maxSizeMB);
} else {
indexDir = origIndexDir;
}
} else {
indexDir = origIndexDir;
}
// Rather than rely on IndexWriter/TaxonomyWriter to
// figure out if an index is new or not by passing
// CREATE_OR_APPEND (which can be dangerous), we
// already know the intention from the app (whether
// it called createIndex vs openIndex), so we make it
// explicit here:
IndexWriterConfig.OpenMode openMode;
if (doCreate) {
// nocommit shouldn't we set doCreate=false after we've done the create? make test!
openMode = IndexWriterConfig.OpenMode.CREATE;
} else {
openMode = IndexWriterConfig.OpenMode.APPEND;
}
Path taxoDirFile;
if (rootDir == null) {
taxoDirFile = null;
} else {
taxoDirFile = rootDir.resolve("taxonomy");
}
taxoDir = indexState.df.open(taxoDirFile, indexState.globalState.getConfiguration().getPreloadConfig());
taxoSnapshots = new PersistentSnapshotDeletionPolicy(new KeepOnlyLastCommitDeletionPolicy(), taxoDir, IndexWriterConfig.OpenMode.CREATE_OR_APPEND);
taxoWriter = new DirectoryTaxonomyWriter(taxoDir, openMode) {
@Override
protected IndexWriterConfig createIndexWriterConfig(IndexWriterConfig.OpenMode openMode) {
IndexWriterConfig iwc = super.createIndexWriterConfig(openMode);
iwc.setIndexDeletionPolicy(taxoSnapshots);
return iwc;
}
@Override
protected IndexWriter openIndexWriter(Directory dir, IndexWriterConfig iwc) throws IOException {
IndexWriter w = super.openIndexWriter(dir, iwc);
taxoInternalWriter = w;
return w;
}
};
writer = new IndexWriter(indexDir, indexState.getIndexWriterConfig(openMode, origIndexDir, shardOrd));
snapshots = (PersistentSnapshotDeletionPolicy) writer.getConfig().getIndexDeletionPolicy();
// loads its commits after writer calls .onInit:
for (IndexCommit c : snapshots.getSnapshots()) {
long gen = c.getGeneration();
SegmentInfos sis = SegmentInfos.readCommit(origIndexDir, IndexFileNames.fileNameFromGeneration(IndexFileNames.SEGMENTS, "", gen));
snapshotGenToVersion.put(c.getGeneration(), sis.getVersion());
}
// nocommit must also pull snapshots for taxoReader?
manager = new SearcherTaxonomyManager(writer, true, new ShardSearcherFactory(true, true), taxoWriter);
restartReopenThread();
startSearcherPruningThread(indexState.globalState.getShutdownLatch());
started = true;
} finally {
if (!started) {
IOUtils.closeWhileHandlingException(reopenThread, manager, writer, taxoWriter, searcherPruningThread, slm, indexDir, taxoDir);
writer = null;
}
}
}
use of org.apache.lucene.facet.taxonomy.SearcherTaxonomyManager in project exist by eXist-db.
the class LuceneIndex method open.
@Override
public void open() throws DatabaseConfigurationException {
Path dir = getDataDir().resolve(getDirName());
Path taxoDir = dir.resolve(TAXONOMY_DIR_NAME);
if (LOG.isDebugEnabled())
LOG.debug("Opening Lucene index directory: {}", dir.toAbsolutePath().toString());
IndexWriter writer = null;
try {
if (Files.exists(dir)) {
if (!Files.isDirectory(dir))
throw new DatabaseConfigurationException("Lucene index location is not a directory: " + dir.toAbsolutePath().toString());
} else {
Files.createDirectories(taxoDir);
}
directory = FSDirectory.open(dir.toFile());
taxoDirectory = FSDirectory.open(taxoDir.toFile());
final IndexWriterConfig idxWriterConfig = new IndexWriterConfig(LUCENE_VERSION_IN_USE, defaultAnalyzer);
idxWriterConfig.setRAMBufferSizeMB(bufferSize);
cachedWriter = new IndexWriter(directory, idxWriterConfig);
cachedTaxonomyWriter = new DirectoryTaxonomyWriter(taxoDirectory);
searcherManager = new SearcherTaxonomyManager(cachedWriter, true, null, cachedTaxonomyWriter);
readerManager = new ReaderManager(cachedWriter, true);
} catch (IOException e) {
throw new DatabaseConfigurationException("Exception while reading lucene index directory: " + e.getMessage(), e);
} finally {
releaseWriter(writer);
}
}
Aggregations