// ============================= ADDITIONAL METHODS ==================================== // This is a typical search on a Lucene's index file. private static void Search(string searchTerm, Lucene.Net.Search.IndexSearcher searcher, QueryParser parser, Directory indexDirectory, int totalDocuments) { // Supply conditions Query query = parser.Parse(searchTerm); // Will store the results (hits). TopScoreDocCollector collector = TopScoreDocCollector.Create(totalDocuments, true); searcher.Search(query, collector); ScoreDoc[] hits = collector.TopDocs().ScoreDocs; int counter = 0; // printing out the results foreach (ScoreDoc item in hits) { int docID = item.Doc; Document d = searcher.Doc(docID); // Call DisplayMessage(d); to display the message. DisplayMessage(d, searchTerm); counter++; } if (counter != 0) { Console.WriteLine("Found {0} messages that match your search term.", counter); } else { Console.WriteLine("There were no results matching your search request.\nSorry :("); } Console.WriteLine("=============================="); }