var directory = FSDirectory.Open(new DirectoryInfo(indexFolderPath)); var indexReader = DirectoryReader.Open(directory); var indexSearcher = new IndexSearcher(indexReader); var queryParser = new QueryParser(LuceneVersion, "Title", new StandardAnalyzer(LuceneVersion)); var query = queryParser.Parse("Title:technology"); var hits = indexSearcher.Search(query, null, 20, Sort.RELEVANCE).ScoreDocs;
var directory = FSDirectory.Open(new DirectoryInfo(indexFolderPath)); var indexReader = DirectoryReader.Open(directory); var indexSearcher = new IndexSearcher(indexReader); var queryParser = new QueryParser(LuceneVersion, "Title", new StandardAnalyzer(LuceneVersion)); var query = queryParser.Parse("Title:technolgy~"); var hits = indexSearcher.Search(query, null, 20, Sort.RELEVANCE).ScoreDocs;This code searches for documents that contain words similar to "technology" (with one character difference) in the title field. Overall, Lucene.Net.Search.IndexSearcher is a powerful tool provided by the Lucene.NET library for searching an index of documents.
Applications usually need only call the inherited {@link #Search(Query)} or {@link #Search(Query,Filter)} methods. For performance reasons it is recommended to open only one IndexSearcher and use it for all of your searches.
Note that you can only access Hits from an IndexSearcher as long as it is not yet closed, otherwise an IOException will be thrown.