protected Lucene.Net.Store.Directory OpenOrCreateLuceneDirectory( IndexDefinition indexDefinition, string indexName = null, bool createIfMissing = true) { Lucene.Net.Store.Directory directory; if (indexDefinition.IsTemp || configuration.RunInMemory) { directory = new RAMDirectory(); new IndexWriter(directory, dummyAnalyzer, IndexWriter.MaxFieldLength.UNLIMITED).Dispose(); // creating index structure } else { var indexDirectory = indexName ?? IndexDefinitionStorage.FixupIndexName(indexDefinition.Name, path); var indexFullPath = Path.Combine(path, MonoHttpUtility.UrlEncode(indexDirectory)); directory = new LuceneCodecDirectory(indexFullPath, documentDatabase.IndexCodecs.OfType <AbstractIndexCodec>()); if (!IndexReader.IndexExists(directory)) { if (createIfMissing == false) { throw new InvalidOperationException("Index does not exists: " + indexDirectory); } WriteIndexVersion(directory); //creating index structure if we need to new IndexWriter(directory, dummyAnalyzer, IndexWriter.MaxFieldLength.UNLIMITED).Dispose(); } else { EnsureIndexVersionMatches(indexName, directory); if (directory.FileExists("write.lock")) // force lock release, because it was still open when we shut down { IndexWriter.Unlock(directory); // for some reason, just calling unlock doesn't remove this file directory.DeleteFile("write.lock"); } if (directory.FileExists("writing-to-index.lock")) // we had an unclean shutdown { if (configuration.ResetIndexOnUncleanShutdown) { throw new InvalidOperationException("Rude shutdown detected on: " + indexDirectory); } CheckIndexAndRecover(directory, indexDirectory); directory.DeleteFile("writing-to-index.lock"); } } } return(directory); }
protected Lucene.Net.Store.Directory OpenOrCreateLuceneDirectory(IndexDefinition indexDefinition, bool createIfMissing = true) { Lucene.Net.Store.Directory directory; if (configuration.RunInMemory || (indexDefinition.IsMapReduce == false && // there is no point in creating map/reduce indexes in memory, we write the intermediate results to disk anyway indexDefinitionStorage.IsNewThisSession(indexDefinition) && indexDefinition.DisableInMemoryIndexing == false && configuration.DisableInMemoryIndexing == false)) { directory = new RAMDirectory(); new IndexWriter(directory, dummyAnalyzer, IndexWriter.MaxFieldLength.UNLIMITED).Dispose(); // creating index structure } else { var indexDirectory = indexDefinition.IndexId.ToString(); var indexFullPath = Path.Combine(path, indexDirectory); directory = new LuceneCodecDirectory(indexFullPath, documentDatabase.IndexCodecs.OfType<AbstractIndexCodec>()); if (!IndexReader.IndexExists(directory)) { if (createIfMissing == false) throw new InvalidOperationException(string.Format("Index directory '{0}' does not exists for '{1}' index.", indexFullPath, indexDefinition.Name)); WriteIndexVersion(directory, indexDefinition); //creating index structure if we need to new IndexWriter(directory, dummyAnalyzer, IndexWriter.MaxFieldLength.UNLIMITED).Dispose(); } else { EnsureIndexVersionMatches(directory, indexDefinition); if (directory.FileExists("write.lock"))// force lock release, because it was still open when we shut down { IndexWriter.Unlock(directory); // for some reason, just calling unlock doesn't remove this file directory.DeleteFile("write.lock"); } if (directory.FileExists("writing-to-index.lock")) // we had an unclean shutdown { if (configuration.ResetIndexOnUncleanShutdown) throw new InvalidOperationException(string.Format("Rude shutdown detected on '{0}' index in '{1}' directory.", indexDefinition.Name, indexFullPath)); CheckIndexAndTryToFix(directory, indexDefinition); directory.DeleteFile("writing-to-index.lock"); } } } return directory; }
protected Lucene.Net.Store.Directory OpenOrCreateLuceneDirectory( IndexDefinition indexDefinition, string indexName = null, bool createIfMissing = true) { Lucene.Net.Store.Directory directory; if (indexDefinition.IsTemp || configuration.RunInMemory) { directory = new RAMDirectory(); new IndexWriter(directory, dummyAnalyzer, IndexWriter.MaxFieldLength.UNLIMITED).Dispose(); // creating index structure } else { var indexDirectory = indexName ?? IndexDefinitionStorage.FixupIndexName(indexDefinition.Name, path); var indexFullPath = Path.Combine(path, MonoHttpUtility.UrlEncode(indexDirectory)); directory = new LuceneCodecDirectory(indexFullPath, documentDatabase.IndexCodecs.OfType<AbstractIndexCodec>()); if (!IndexReader.IndexExists(directory)) { if (createIfMissing == false) throw new InvalidOperationException("Index does not exists: " + indexDirectory); WriteIndexVersion(directory); //creating index structure if we need to new IndexWriter(directory, dummyAnalyzer, IndexWriter.MaxFieldLength.UNLIMITED).Dispose(); } else { EnsureIndexVersionMatches(indexName, directory); if (directory.FileExists("write.lock"))// force lock release, because it was still open when we shut down { IndexWriter.Unlock(directory); // for some reason, just calling unlock doesn't remove this file directory.DeleteFile("write.lock"); } if (directory.FileExists("writing-to-index.lock")) // we had an unclean shutdown { if (configuration.ResetIndexOnUncleanShutdown) throw new InvalidOperationException("Rude shutdown detected on: " + indexDirectory); CheckIndexAndRecover(directory, indexDirectory); directory.DeleteFile("writing-to-index.lock"); } } } return directory; }