Using Collectors

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 ...

Get Lucene 4 Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.