Package org.apache.lucene.search
Class TopFieldCollector
- java.lang.Object
-
- org.apache.lucene.search.TopDocsCollector<FieldValueHitQueue.Entry>
-
- org.apache.lucene.search.TopFieldCollector
-
- All Implemented Interfaces:
Collector
- Direct Known Subclasses:
TopFieldCollector.PagingFieldCollector
,TopFieldCollector.SimpleFieldCollector
public abstract class TopFieldCollector extends TopDocsCollector<FieldValueHitQueue.Entry>
ACollector
that sorts bySortField
usingFieldComparator
s.See the
create(org.apache.lucene.search.Sort, int, int)
method for instantiating a TopFieldCollector.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static class
TopFieldCollector.PagingFieldCollector
private static class
TopFieldCollector.SimpleFieldCollector
private class
TopFieldCollector.TopFieldLeafCollector
-
Field Summary
Fields Modifier and Type Field Description (package private) FieldValueHitQueue.Entry
bottom
(package private) boolean
canSetMinScore
(package private) int
docBase
private static ScoreDoc[]
EMPTY_SCOREDOCS
(package private) FieldComparator<?>
firstComparator
(package private) HitsThresholdChecker
hitsThresholdChecker
(package private) float
minCompetitiveScore
(package private) MaxScoreAccumulator
minScoreAcc
(package private) boolean
needsScores
(package private) int
numComparators
(package private) int
numHits
(package private) boolean
queueFull
(package private) ScoreMode
scoreMode
(package private) java.lang.Boolean
searchSortPartOfIndexSort
-
Fields inherited from class org.apache.lucene.search.TopDocsCollector
EMPTY_TOPDOCS, pq, totalHits, totalHitsRelation
-
-
Constructor Summary
Constructors Modifier Constructor Description private
TopFieldCollector(FieldValueHitQueue<FieldValueHitQueue.Entry> pq, int numHits, HitsThresholdChecker hitsThresholdChecker, boolean needsScores, MaxScoreAccumulator minScoreAcc)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description (package private) void
add(int slot, int doc)
(package private) static boolean
canEarlyTerminate(Sort searchSort, Sort indexSort)
private static boolean
canEarlyTerminateOnDocId(Sort searchSort)
private static boolean
canEarlyTerminateOnPrefix(Sort searchSort, Sort indexSort)
static TopFieldCollector
create(Sort sort, int numHits, int totalHitsThreshold)
Creates a newTopFieldCollector
from the given arguments.static TopFieldCollector
create(Sort sort, int numHits, FieldDoc after, int totalHitsThreshold)
Creates a newTopFieldCollector
from the given arguments.(package private) static TopFieldCollector
create(Sort sort, int numHits, FieldDoc after, HitsThresholdChecker hitsThresholdChecker, MaxScoreAccumulator minScoreAcc)
Same as above with additional parameters to allow passing in the threshold checker and the max score accumulator.static CollectorManager<TopFieldCollector,TopFieldDocs>
createSharedManager(Sort sort, int numHits, FieldDoc after, int totalHitsThreshold)
Create a CollectorManager which uses a shared hit counter to maintain number of hits and a sharedMaxScoreAccumulator
to propagate the minimum score accross segments if the primary sort is by relevancy.boolean
isEarlyTerminated()
Return whether collection terminated early.protected TopDocs
newTopDocs(ScoreDoc[] results, int start)
Returns aTopDocs
instance containing the given results.protected void
populateResults(ScoreDoc[] results, int howMany)
Populates the results array with the ScoreDoc instances.static void
populateScores(ScoreDoc[] topDocs, IndexSearcher searcher, Query query)
Populatescores
of the giventopDocs
.ScoreMode
scoreMode()
Indicates what features are required from the scorer.TopFieldDocs
topDocs()
Returns the top docs that were collected by this collector.(package private) void
updateBottom(int doc)
protected void
updateGlobalMinCompetitiveScore(Scorable scorer)
protected void
updateMinCompetitiveScore(Scorable scorer)
-
Methods inherited from class org.apache.lucene.search.TopDocsCollector
getTotalHits, topDocs, topDocs, topDocsSize
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.apache.lucene.search.Collector
getLeafCollector
-
-
-
-
Field Detail
-
EMPTY_SCOREDOCS
private static final ScoreDoc[] EMPTY_SCOREDOCS
-
numHits
final int numHits
-
hitsThresholdChecker
final HitsThresholdChecker hitsThresholdChecker
-
firstComparator
final FieldComparator<?> firstComparator
-
canSetMinScore
final boolean canSetMinScore
-
searchSortPartOfIndexSort
java.lang.Boolean searchSortPartOfIndexSort
-
minScoreAcc
final MaxScoreAccumulator minScoreAcc
-
minCompetitiveScore
float minCompetitiveScore
-
numComparators
final int numComparators
-
bottom
FieldValueHitQueue.Entry bottom
-
queueFull
boolean queueFull
-
docBase
int docBase
-
needsScores
final boolean needsScores
-
scoreMode
final ScoreMode scoreMode
-
-
Constructor Detail
-
TopFieldCollector
private TopFieldCollector(FieldValueHitQueue<FieldValueHitQueue.Entry> pq, int numHits, HitsThresholdChecker hitsThresholdChecker, boolean needsScores, MaxScoreAccumulator minScoreAcc)
-
-
Method Detail
-
canEarlyTerminateOnDocId
private static boolean canEarlyTerminateOnDocId(Sort searchSort)
-
canEarlyTerminateOnPrefix
private static boolean canEarlyTerminateOnPrefix(Sort searchSort, Sort indexSort)
-
scoreMode
public ScoreMode scoreMode()
Description copied from interface:Collector
Indicates what features are required from the scorer.
-
updateGlobalMinCompetitiveScore
protected void updateGlobalMinCompetitiveScore(Scorable scorer) throws java.io.IOException
- Throws:
java.io.IOException
-
updateMinCompetitiveScore
protected void updateMinCompetitiveScore(Scorable scorer) throws java.io.IOException
- Throws:
java.io.IOException
-
create
public static TopFieldCollector create(Sort sort, int numHits, int totalHitsThreshold)
Creates a newTopFieldCollector
from the given arguments.NOTE: The instances returned by this method pre-allocate a full array of length
numHits
.- Parameters:
sort
- the sort criteria (SortFields).numHits
- the number of results to collect.totalHitsThreshold
- the number of docs to count accurately. If the query matches more thantotalHitsThreshold
hits then its hit count will be a lower bound. On the other hand if the query matches less than or exactlytotalHitsThreshold
hits then the hit count of the result will be accurate.Integer.MAX_VALUE
may be used to make the hit count accurate, but this will also make query processing slower.- Returns:
- a
TopFieldCollector
instance which will sort the results by the sort criteria.
-
create
public static TopFieldCollector create(Sort sort, int numHits, FieldDoc after, int totalHitsThreshold)
Creates a newTopFieldCollector
from the given arguments.NOTE: The instances returned by this method pre-allocate a full array of length
numHits
.- Parameters:
sort
- the sort criteria (SortFields).numHits
- the number of results to collect.after
- only hits after this FieldDoc will be collectedtotalHitsThreshold
- the number of docs to count accurately. If the query matches more thantotalHitsThreshold
hits then its hit count will be a lower bound. On the other hand if the query matches less than or exactlytotalHitsThreshold
hits then the hit count of the result will be accurate.Integer.MAX_VALUE
may be used to make the hit count accurate, but this will also make query processing slower. Setting totalHitsThreshold less thanInteger.MAX_VALUE
instructs Lucene to skip non-competitive documents whenever possible. For numeric sort fields the skipping functionality works when the same field is indexed both with doc values and points. In this case, there is an assumption that the same data is stored in these points and doc values.- Returns:
- a
TopFieldCollector
instance which will sort the results by the sort criteria.
-
create
static TopFieldCollector create(Sort sort, int numHits, FieldDoc after, HitsThresholdChecker hitsThresholdChecker, MaxScoreAccumulator minScoreAcc)
Same as above with additional parameters to allow passing in the threshold checker and the max score accumulator.
-
createSharedManager
public static CollectorManager<TopFieldCollector,TopFieldDocs> createSharedManager(Sort sort, int numHits, FieldDoc after, int totalHitsThreshold)
Create a CollectorManager which uses a shared hit counter to maintain number of hits and a sharedMaxScoreAccumulator
to propagate the minimum score accross segments if the primary sort is by relevancy.
-
populateScores
public static void populateScores(ScoreDoc[] topDocs, IndexSearcher searcher, Query query) throws java.io.IOException
Populatescores
of the giventopDocs
.- Parameters:
topDocs
- the top docs to populatesearcher
- the index searcher that has been used to computetopDocs
query
- the query that has been used to computetopDocs
- Throws:
java.lang.IllegalArgumentException
- if there is evidence thattopDocs
have been computed against a different searcher or a different query.java.io.IOException
-
add
final void add(int slot, int doc)
-
updateBottom
final void updateBottom(int doc)
-
populateResults
protected void populateResults(ScoreDoc[] results, int howMany)
Description copied from class:TopDocsCollector
Populates the results array with the ScoreDoc instances. This can be overridden in case a different ScoreDoc type should be returned.- Overrides:
populateResults
in classTopDocsCollector<FieldValueHitQueue.Entry>
-
newTopDocs
protected TopDocs newTopDocs(ScoreDoc[] results, int start)
Description copied from class:TopDocsCollector
Returns aTopDocs
instance containing the given results. Ifresults
is null it means there are no results to return, either because there were 0 calls to collect() or because the arguments to topDocs were invalid.- Overrides:
newTopDocs
in classTopDocsCollector<FieldValueHitQueue.Entry>
-
topDocs
public TopFieldDocs topDocs()
Description copied from class:TopDocsCollector
Returns the top docs that were collected by this collector.- Overrides:
topDocs
in classTopDocsCollector<FieldValueHitQueue.Entry>
-
isEarlyTerminated
public boolean isEarlyTerminated()
Return whether collection terminated early.
-
-