CollectorManager (Lucene 10.5.1 core API)
Description: declaration: package: org.apache.lucene.search, interface: CollectorManager

Package org.apache.lucene.search

# Interface CollectorManager<C extends Collector,T>

All Known Implementing Classes:
  `MultiCollectorManager`, `TopFieldCollectorManager`, `TopScoreDocCollectorManager`, `TotalHitCountCollectorManager`

public interface CollectorManager<C extends Collector,T>
A manager of collectors. This class is useful to parallelize execution of search requests and has two main methods:

- `newCollector()` which must return a NEW collector which will be used to collect a certain set of leaves.
- `reduce(Collection)` which will be used to reduce the results of individual collections into a meaningful result. This method is only called after all leaves have been fully collected.

Note: Multiple `LeafCollector`s may be requested for the same `LeafReaderContext` via `Collector.getLeafCollector(LeafReaderContext)` across the different `Collector`s returned by `newCollector()`. Any computation or logic that needs to happen once per segment requires specific handling in the collector manager implementation, because the collection of an entire segment may be split across threads.

See Also:
  - `IndexSearcher.search(Query, CollectorManager)`
WARNING: This API is experimental and might change in incompatible ways in the next release.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `C`
  `newCollector()`
  Return a new `Collector`.
  `T`
  `reduce(Collection<C> collectors)`
  Reduce the results of individual collectors into a meaningful result.

- ## Method Details

  - ### newCollector

    C newCollector() throws IOException
    Return a new `Collector`. This must return a different instance on each call.
    Throws:
      `IOException`

  - ### reduce

    T reduce(Collection<C> collectors) throws IOException
    Reduce the results of individual collectors into a meaningful result. For instance a `TopDocsCollector` would compute the `top docs` of each collector and then merge them using `TopDocs.merge(int, TopDocs[])`. This method must be called after collection is finished on all provided collectors.
    Throws:
      `IOException`