Collector is an advanced feature that deals with the low-level handling of search results data. The implementation of this class is necessary to produce usable search results. When we call the IndexSearcher.search
methods, we are actually already using Collector under the hood. So, what exactly is Collector? You can think of it as a refinery of search results after documents are matched. The matched documents are sent to Collector to score and sort. The default Collector we use in IndexSearcher.search
is called TopScoreDocCollector
. It scores documents using a scorer and sorts results based on the scores.
Normally, you shouldn't have to mess with Collector. However, on a rare occasion when you need more control over how the matched documents are scored, sorted, or even filtered, Collector can be a good place to work on the customization. This is assuming that you have already exhausted the options of custom filter, similarity, and/or analyzer.