title: How do I sort Lucene results by field value using a HitCollector?
body: <p>I'm using the following code to execute a query in Lucene.Net</p>
  
  <pre><code>var collector = new GroupingHitCollector(searcher.GetIndexReader());
  searcher.Search(myQuery, collector);
  resultsCount = collector.Hits.Count;
  </code></pre>
  
  <p>How do I sort these search results based on a field?</p>
  
  <hr>
  
  <h2>Update</h2>
  
  <p>Thanks for <a href="https://stackoverflow.com/questions/497609/sorting-lucene-search-results/500409#500409">your answer</a>. I had tried using <code>TopFieldDocCollector</code> but I got an error saying, <code>"value is too small or too large"</code> when i passed <code>5000</code> as <code>numHits</code> argument value. Please suggest a valid value to pass.</p>