org.apache.lucene.search

## Class EarlyTerminatingSortingCollector

- java.lang.Object
- - org.apache.lucene.search.FilterCollector
  - - org.apache.lucene.search.EarlyTerminatingSortingCollector

- All Implemented Interfaces:
    Collector

      public class EarlyTerminatingSortingCollector
      extends FilterCollector

  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(org.apache.lucene.search.Sort)`. 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.

  WARNING: This API is experimental and might change in incompatible ways in the next release.

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `protected int` | `numDocsToCollect` Number of documents to collect in each segment
    `protected Sort` | `sort` Sort used to sort the search results

    - ### Fields inherited from class org.apache.lucene.search.FilterCollector

      `in`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `EarlyTerminatingSortingCollector(Collector in, Sort sort, int numDocsToCollect)` Create a new `EarlyTerminatingSortingCollector` instance.

  - ### Method Summary

    All Methods Static Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `static boolean` | `canEarlyTerminate(Sort searchSort, Sort mergePolicySort)` Returns whether collection can be early-terminated if it sorts with the provided `Sort` and if segments are merged with the provided `Sort`.
    `LeafCollector` | `getLeafCollector(LeafReaderContext context)` Create a new `collector` to collect the given context.
    `boolean` | `terminatedEarly()`

    - ### Methods inherited from class org.apache.lucene.search.FilterCollector

      `needsScores, toString`

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

- - ### 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.
      Parameters:
        `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.
      Throws:
        `IllegalArgumentException` - if the sort order doesn't allow for early termination with the given merge policy.

  - ### Method Detail

    - #### canEarlyTerminate

          public static boolean canEarlyTerminate(Sort searchSort,
                                                  Sort mergePolicySort)

      Returns whether collection can be early-terminated if it sorts with the provided `Sort` and if segments are merged with the provided `Sort`.

    - #### getLeafCollector

          public LeafCollector getLeafCollector(LeafReaderContext context)
                                         throws IOException

      Description copied from interface: `Collector`
      Create a new `collector` to collect the given context.
      Specified by:
        `getLeafCollector` in interface `Collector`
      Overrides:
        `getLeafCollector` in class `FilterCollector`
      Parameters:
        `context` - next atomic reader context
      Throws:
        `IOException`

    - #### terminatedEarly

          public boolean terminatedEarly()

Copyright © 2000-2019 Apache Software Foundation. All Rights Reserved.