Class BlockGroupingCollectorManager<T>

java.lang.Object
org.apache.lucene.search.grouping.BlockGroupingCollectorManager<T>
All Implemented Interfaces:
CollectorManager<BlockGroupingCollector,TopGroups<T>>

public class BlockGroupingCollectorManager<T> extends Object implements CollectorManager<BlockGroupingCollector,TopGroups<T>>
A CollectorManager for BlockGroupingCollector that merges results from multiple collectors into a single TopGroups. This is intended for use with concurrent search, where each slice is searched by a separate BlockGroupingCollector.

Documents must be indexed as blocks using IndexWriter.addDocuments() or IndexWriter.updateDocuments().

NOTE: All documents in a group block must be processed by the same BlockGroupingCollector instance. This means that the IndexSearcher's slices must not split a segment in a way that places documents from the same block into different slices. The default IndexSearcher.slices(java.util.List<org.apache.lucene.index.LeafReaderContext>) implementation (inter-segment only) satisfies this constraint. If intra-segment concurrency is desired, the caller must override IndexSearcher.slices(java.util.List<org.apache.lucene.index.LeafReaderContext>) to ensure each doc block falls entirely within one slice.

See BlockGroupingCollector for more details.

Example usage:

 IndexSearcher searcher = ...; // your IndexSearcher
 Query lastDocPerGroupQuery = new TermQuery(new Term("groupEnd", "true"));
 Weight lastDocPerGroup = searcher.createWeight(
     searcher.rewrite(lastDocPerGroupQuery), ScoreMode.COMPLETE_NO_SCORES, 1);

 BlockGroupingCollectorManager<BytesRef> manager = new BlockGroupingCollectorManager<>(
     Sort.RELEVANCE,   // groupSort
     0,                // groupOffset
     10,               // topNGroups
     true,             // needsScores
     lastDocPerGroup,
     Sort.RELEVANCE,   // withinGroupSort
     0,                // withinGroupOffset
     5);               // maxDocsPerGroup

 TopGroups<BytesRef> result = searcher.search(query, manager);
 
WARNING: This API is experimental and might change in incompatible ways in the next release.
  • Constructor Details

    • BlockGroupingCollectorManager

      public BlockGroupingCollectorManager(Sort groupSort, int groupOffset, int topNGroups, boolean needsScores, Weight lastDocPerGroup, Sort withinGroupSort, int withinGroupOffset, int maxDocsPerGroup)
      Creates a new BlockGroupingCollectorManager.
      Parameters:
      groupSort - the sort used to rank groups
      groupOffset - the offset into the groups to start returning from
      topNGroups - the number of top groups to collect
      needsScores - whether scores are needed (must be true if groupSort or withinGroupSort uses scores)
      lastDocPerGroup - a Weight that matches the last document in each group block
      withinGroupSort - the sort used to rank documents within each group
      withinGroupOffset - the offset into each group's documents to start returning from
      maxDocsPerGroup - the maximum number of documents to return per group
  • Method Details