Class EarlyTerminatingSortingCollector

  • All Implemented Interfaces:

    public class EarlyTerminatingSortingCollector
    extends FilterCollector
    Pass trackTotalHits=false to TopFieldCollector instead of using this class.
    A Collector that early terminates collection of documents on a per-segment basis, if the segment was sorted according to the given Sort.

    NOTE: the Collector detects segments sorted according to a an IndexWriterConfig.setIndexSort( Also, it collects up to a specified numDocsToCollect 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 TopDocs will be correct. However the total of hit count will be vastly underestimated since not all matching documents will have been collected.

    • Field Detail

      • sort

        protected final Sort sort
        Sort used to sort the search results
      • numDocsToCollect

        protected final int numDocsToCollect
        Number of documents to collect in each segment
    • Constructor Detail

      • EarlyTerminatingSortingCollector

        public EarlyTerminatingSortingCollector​(Collector in,
                                                Sort sort,
                                                int numDocsToCollect)
        Create a new EarlyTerminatingSortingCollector instance.
        in - the collector to wrap
        sort - the sort you are sorting the search results on
        numDocsToCollect - the number of documents to collect on each segment. When wrapping a TopDocsCollector, this number should be the number of hits.
        IllegalArgumentException - if the sort order doesn't allow for early termination with the given merge policy.