I’m using the following code to execute a query in Lucene.Net
var collector = new GroupingHitCollector(searcher.GetIndexReader()); searcher.Search(myQuery, collector); resultsCount = collector.Hits.Count;
How do I sort these search results based on a field?
Update
Thanks for your answer. I had tried using TopFieldDocCollector but I got an error saying, 'value is too small or too large' when i passed 5000 as numHits argument value. Please suggest a valid value to pass.
The
search.Searcher.searchmethod will accept asearch.Sortparameter, which can be constructed as simply as:However, there are some limitations on which fields can be sorted on – they need to be indexed but not tokenized, and the values convertible to
Strings,Floats orIntegers.Lucene in Action covers all of the details, as well as sorting by multiple fields and so on.