I'm using the Sitecore WCMS and have a piece of C# code that uses Lucene.net to search an index based on some criteria. I'm using the IndexSearcher class as follows:
Database webDB = Sitecore.Context.Database;
Sitecore.Data.Indexing.Index index = webDB.Indexes["CampusNewsIndex"];
IndexSearcher indexSearcher = index.GetSearcher(webDB);
BooleanQuery completeQuery = new BooleanQuery();
// build completeQuery
Hits hits = indexSearcher.Search(completeQuery, sort);
for (int i = 0; i < hits.length(); i++)
{
returnItems[i] = Sitecore.Data.Indexing.Index.GetItem(hits.Doc(i), Sitecore.Context.Database);
}
This code works fine if results are returned. However, if "hits" has no results, hits.length() returns 1 even though it makes logical sense for it to return 0. Does anybody know how I can tell if the query returned no results?