I used this code to perform a search of a Lucene.Net index.
Lucene.Net.Store..Directory directory =
Lucene.Net.Store.FSDirectory
.Open(new DirectoryInfo(textBoxSearchIndex.Text));
Lucene.Net.Analysis.Analyzer analyzer =
new Lucene.Net.Analysis.Standard
.StandardAnalyzer(LuceneUtil.Version.LUCENE_29);
Lucene.Net.Search.Searcher searcher =
new Lucene.Net.Search
.IndexSearcher(LuceneIndex.IndexReader
.Open(directory, true));
Lucene.Net.Search.Query query =
new Lucene.Net.QueryParsers
.QueryParser(LuceneUtil.Version.LUCENE_29,
"contents", analyzer)
.Parse(textBoxSearch.Text);
Lucene.Net.Search.Hits hits = searcher.Search(query);
Put these lines of code within a for loop.
LuceneDocument.Document doc = hits.Doc(i);
string result = "Contents: " + doc.Get("contents");
Reading in the source code I found that the Search method which returns a Hits class will be depreciated in 3.0. Even though the above worked, I decided to implement a solution that will work with future versions of Lucene.Net. Below is what I change my code to look like.
LuceneStore.Directory directory =
LuceneStore.FSDirectory
.Open(new DirectoryInfo(textBoxSearchIndex.Text));
const int HITS_PER_PAGE = 20;
Analyzer analyzer =
new StandardAnalyzer(LuceneUtil.Version.LUCENE_29);
LuceneSearch.Query query =
new LuceneQueryParsers
.QueryParser(LuceneUtil.Version.LUCENE_29,
"contents", analyzer)
.Parse(textBoxSearch.Text);
LuceneSearch.Searcher searcher =
new LuceneSearch.IndexSearcher(LuceneIndex.IndexReader
.Open(directory, true));
TopScoreDocCollector collector =
TopScoreDocCollector.create(HITS_PER_PAGE, true);
searcher.Search(query, collector);
ScoreDoc[] hits = collector.TopDocs().scoreDocs;
Put these lines of code within a for loop.
int docId = hits[i].doc;
LuceneDocument.Document doc = searcher.Doc(docId);
string result = "Contents: " + doc.Get("contents");