var directory = FSDirectory.Open("path/to/index"); var reader = DirectoryReader.Open(directory); var searcher = new IndexSearcher(reader); var query = new TermQuery(new Term("content", "lucene")); var topDocs = searcher.Search(query, 10); foreach (var scoreDoc in topDocs.ScoreDocs) { var doc = searcher.Doc(scoreDoc.Doc); Console.WriteLine(doc.GetField("title")); }
var index1 = FSDirectory.Open("path/to/index1"); var index2 = FSDirectory.Open("path/to/index2"); var readers = new List{ DirectoryReader.Open(index1), DirectoryReader.Open(index2) }; var mergedIndexReader = new MultiReader(readers.ToArray());
PM> Install-Package Lucene.Net
There are two different types of IndexReaders:
IndexReader instances for indexes on disk are usually constructed with a call to one of the static DirectoryReader.open()
methods, e.g. DirectoryReader#open(Lucene.Net.Store.Directory). DirectoryReader implements the CompositeReader interface, it is not possible to directly get postings.
For efficiency, in this API documents are often referred to via document numbers, non-negative integers which each name a unique document in the index. These document numbers are ephemeral -- they may change as documents are added to and deleted from an index. Clients should thus not rely on a given document having the same number between sessions.
NOTE: {@link IndexReader} instances are completely thread safe, meaning multiple threads can call any of its methods, concurrently. If your application requires external synchronization, you should not synchronize on the IndexReader
instance; use your own (non-Lucene) objects instead.