public class EarlyTerminatingSortingCollector extends FilterCollector
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 sorted segments according to
SortingMergePolicy
, so it's best used in conjunction with it. 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 underestimated since not all matching documents will have
been collected.
NOTE: This Collector
uses Sort.toString()
to detect
whether a segment was sorted with the same Sort
. This has
two implications:
IndexWriter
's
SortingMergePolicy
to sort according to another criterion and if both
the old and the new Sort
s have the same identifier, this
Collector
will incorrectly detect sorted segments.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
|
in
Constructor and Description |
---|
EarlyTerminatingSortingCollector(Collector in,
Sort sort,
int numDocsToCollect,
SortingMergePolicy mergePolicy)
Create a new
EarlyTerminatingSortingCollector instance. |
Modifier and Type | Method and Description |
---|---|
static boolean |
canEarlyTerminate(Sort sort,
SortingMergePolicy mergePolicy)
Returns whether collection can be early-terminated if it sorts with the
provided
Sort and if segments are merged with the provided
SortingMergePolicy . |
LeafCollector |
getLeafCollector(LeafReaderContext context) |
needsScores, toString
protected final Sort sort
protected final int numDocsToCollect
public EarlyTerminatingSortingCollector(Collector in, Sort sort, int numDocsToCollect, SortingMergePolicy mergePolicy)
EarlyTerminatingSortingCollector
instance.in
- the collector to wrapsort
- the sort you are sorting the search results onnumDocsToCollect
- 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.public static boolean canEarlyTerminate(Sort sort, SortingMergePolicy mergePolicy)
Sort
and if segments are merged with the provided
SortingMergePolicy
.public LeafCollector getLeafCollector(LeafReaderContext context) throws IOException
getLeafCollector
in interface Collector
getLeafCollector
in class FilterCollector
IOException
Copyright © 2000-2015 Apache Software Foundation. All Rights Reserved.