java.lang.Object
org.apache.lucene.search.TotalHitCountCollectorManager
- All Implemented Interfaces:
CollectorManager<TotalHitCountCollector,
Integer>
public class TotalHitCountCollectorManager
extends Object
implements CollectorManager<TotalHitCountCollector,Integer>
Collector manager based on
TotalHitCountCollector
that allows users to parallelize
counting the number of hits, expected to be used mostly wrapped in MultiCollectorManager
.
For cases when this is the only collector manager used, IndexSearcher.count(Query)
should
be called instead of IndexSearcher.search(Query, CollectorManager)
as the former is
faster whenever the count can be returned directly from the index statistics.-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate static class
-
Field Summary
FieldsModifier and TypeFieldDescriptionInternal state shared across the different collectors that this collector manager creates.private final boolean
-
Constructor Summary
ConstructorsConstructorDescriptionTotalHitCountCollectorManager
(IndexSearcher.LeafSlice[] leafSlices) Creates a new total hit count collector manager, providing the array of leaf slices that search targets, which can be retrieved viaIndexSearcher.getSlices()
for the searcher. -
Method Summary
Modifier and TypeMethodDescriptionprivate static boolean
hasSegmentPartitions
(IndexSearcher.LeafSlice[] leafSlices) Return a newCollector
.reduce
(Collection<TotalHitCountCollector> collectors) Reduce the results of individual collectors into a meaningful result.
-
Field Details
-
hasSegmentPartitions
private final boolean hasSegmentPartitions -
earlyTerminatedMap
Internal state shared across the different collectors that this collector manager creates. This is necessary to support intra-segment concurrency. We track leaves seen as an argument ofCollector.getLeafCollector(LeafReaderContext)
calls, to ensure correctness: if the first partition of a segment early terminates, count has been already retrieved for the entire segment hence subsequent partitions of the same segment should also early terminate without further incrementing hit count. If the first partition of a segment computes hit counts, subsequent partitions of the same segment should do the same, to prevent their counts from being retrieved fromLRUQueryCache
(which returns counts for the entire segment while we'd need only that of the current leaf partition).
-
-
Constructor Details
-
TotalHitCountCollectorManager
Creates a new total hit count collector manager, providing the array of leaf slices that search targets, which can be retrieved viaIndexSearcher.getSlices()
for the searcher.- Parameters:
leafSlices
- the slices that the searcher targets. Used to optimize the collection depending on whether segments have been partitioned into partitions or not.
-
-
Method Details
-
hasSegmentPartitions
-
newCollector
Description copied from interface:CollectorManager
Return a newCollector
. This must return a different instance on each call.- Specified by:
newCollector
in interfaceCollectorManager<TotalHitCountCollector,
Integer> - Throws:
IOException
-
reduce
Description copied from interface:CollectorManager
Reduce the results of individual collectors into a meaningful result. For instance aTopDocsCollector
would compute thetop docs
of each collector and then merge them usingTopDocs.merge(int, TopDocs[])
. This method must be called after collection is finished on all provided collectors.- Specified by:
reduce
in interfaceCollectorManager<TotalHitCountCollector,
Integer> - Throws:
IOException
-