Class EarlyTerminatingSortingCollector

java.lang.Object
org.apache.lucene.search.Collector
org.apache.lucene.index.sorter.EarlyTerminatingSortingCollector

public class EarlyTerminatingSortingCollector extends Collector
A Collector that early terminates collection of documents on a per-segment basis, if the segment was sorted according to the given Sorter.

NOTE: the Collector detects sorted segments according to SortingMergePolicy, so it's best used in conjunction with it. Also, it collects up to a specified num docs from each segment, and therefore is mostly suitable for use in conjunction with collectors such as TopDocsCollector, and not e.g. TotalHitCountCollector.

NOTE: If you wrap a TopDocsCollector that sorts in the same order as the index order, the returned TopDocsCollector.topDocs() will be correct. However the total of hit count will be underestimated since not all matching documents will have been collected.

NOTE: This Collector uses Sorter.getID() to detect whether a segment was sorted with the same Sorter as the one given in EarlyTerminatingSortingCollector(Collector, Sorter, int). This has two implications:

  • if Sorter.getID() is not implemented correctly and returns different identifiers for equivalent Sorters, this collector will not detect sorted segments,
  • if you suddenly change the IndexWriter's SortingMergePolicy to sort according to another criterion and if both the old and the new Sorters have the same identifier, this Collector will incorrectly detect sorted segments.