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
public abstract class TopFieldCollector extends TopDocsCollector<FieldValueHitQueue.Entry>
ACollectorthat sorts bySortFieldusingFieldComparators.See the
create(org.apache.lucene.search.Sort, int, boolean, boolean, boolean, boolean)method for instantiating a TopFieldCollector.- WARNING: This API is experimental and might change in incompatible ways in the next release.
-
-
Field Summary
-
Fields inherited from class org.apache.lucene.search.TopDocsCollector
EMPTY_TOPDOCS, pq, totalHits
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description static TopFieldCollectorcreate(Sort sort, int numHits, boolean fillFields, boolean trackDocScores, boolean trackMaxScore)Deprecated.static TopFieldCollectorcreate(Sort sort, int numHits, boolean fillFields, boolean trackDocScores, boolean trackMaxScore, boolean trackTotalHits)Creates a newTopFieldCollectorfrom the given arguments.static TopFieldCollectorcreate(Sort sort, int numHits, FieldDoc after, boolean fillFields, boolean trackDocScores, boolean trackMaxScore)Deprecated.static TopFieldCollectorcreate(Sort sort, int numHits, FieldDoc after, boolean fillFields, boolean trackDocScores, boolean trackMaxScore, boolean trackTotalHits)Creates a newTopFieldCollectorfrom the given arguments.booleanisEarlyTerminated()Return whether collection terminated early.booleanneedsScores()Indicates if document scores are needed by this collector.protected TopDocsnewTopDocs(ScoreDoc[] results, int start)Returns aTopDocsinstance containing the given results.protected voidpopulateResults(ScoreDoc[] results, int howMany)Populates the results array with the ScoreDoc instances.TopFieldDocstopDocs()Returns the top docs that were collected by this collector.-
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
-
-
-
-
Method Detail
-
needsScores
public boolean needsScores()
Description copied from interface:CollectorIndicates if document scores are needed by this collector.- Returns:
trueif scores are needed.
-
create
@Deprecated public static TopFieldCollector create(Sort sort, int numHits, boolean fillFields, boolean trackDocScores, boolean trackMaxScore)
Deprecated.Creates a newTopFieldCollectorfrom 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.fillFields- specifies whether the actual field values should be returned on the results (FieldDoc).trackDocScores- specifies whether document scores should be tracked and set on the results. Note that if set to false, then the results' scores will be set to Float.NaN. Setting this to true affects performance, as it incurs the score computation on each competitive result. Therefore if document scores are not required by the application, it is recommended to set it to false.trackMaxScore- specifies whether the query's maxScore should be tracked and set on the resultingTopDocs. Note that if set to false,TopDocs.getMaxScore()returns Float.NaN. Setting this to true affects performance as it incurs the score computation on each result. Also, setting this true automatically setstrackDocScoresto true as well.- Returns:
- a
TopFieldCollectorinstance which will sort the results by the sort criteria.
-
create
public static TopFieldCollector create(Sort sort, int numHits, boolean fillFields, boolean trackDocScores, boolean trackMaxScore, boolean trackTotalHits)
Creates a newTopFieldCollectorfrom 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.fillFields- specifies whether the actual field values should be returned on the results (FieldDoc).trackDocScores- specifies whether document scores should be tracked and set on the results. Note that if set to false, then the results' scores will be set to Float.NaN. Setting this to true affects performance, as it incurs the score computation on each competitive result. Therefore if document scores are not required by the application, it is recommended to set it to false.trackMaxScore- specifies whether the query's maxScore should be tracked and set on the resultingTopDocs. Note that if set to false,TopDocs.getMaxScore()returns Float.NaN. Setting this to true affects performance as it incurs the score computation on each result. Also, setting this true automatically setstrackDocScoresto true as well.trackTotalHits- specifies whether the total number of hits should be tracked. If set to false, the value ofTopDocs.totalHitswill be approximated.- Returns:
- a
TopFieldCollectorinstance which will sort the results by the sort criteria.
-
create
@Deprecated public static TopFieldCollector create(Sort sort, int numHits, FieldDoc after, boolean fillFields, boolean trackDocScores, boolean trackMaxScore)
Deprecated.Creates a newTopFieldCollectorfrom 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 collectedfillFields- specifies whether the actual field values should be returned on the results (FieldDoc).trackDocScores- specifies whether document scores should be tracked and set on the results. Note that if set to false, then the results' scores will be set to Float.NaN. Setting this to true affects performance, as it incurs the score computation on each competitive result. Therefore if document scores are not required by the application, it is recommended to set it to false.trackMaxScore- specifies whether the query's maxScore should be tracked and set on the resultingTopDocs. Note that if set to false,TopDocs.getMaxScore()returns Float.NaN. Setting this to true affects performance as it incurs the score computation on each result. Also, setting this true automatically setstrackDocScoresto true as well.- Returns:
- a
TopFieldCollectorinstance which will sort the results by the sort criteria.
-
create
public static TopFieldCollector create(Sort sort, int numHits, FieldDoc after, boolean fillFields, boolean trackDocScores, boolean trackMaxScore, boolean trackTotalHits)
Creates a newTopFieldCollectorfrom 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 collectedfillFields- specifies whether the actual field values should be returned on the results (FieldDoc).trackDocScores- specifies whether document scores should be tracked and set on the results. Note that if set to false, then the results' scores will be set to Float.NaN. Setting this to true affects performance, as it incurs the score computation on each competitive result. Therefore if document scores are not required by the application, it is recommended to set it to false.trackMaxScore- specifies whether the query's maxScore should be tracked and set on the resultingTopDocs. Note that if set to false,TopDocs.getMaxScore()returns Float.NaN. Setting this to true affects performance as it incurs the score computation on each result. Also, setting this true automatically setstrackDocScoresto true as well.trackTotalHits- specifies whether the total number of hits should be tracked. If set to false, the value ofTopDocs.totalHitswill be approximated.- Returns:
- a
TopFieldCollectorinstance which will sort the results by the sort criteria.
-
populateResults
protected void populateResults(ScoreDoc[] results, int howMany)
Description copied from class:TopDocsCollectorPopulates the results array with the ScoreDoc instances. This can be overridden in case a different ScoreDoc type should be returned.- Overrides:
populateResultsin classTopDocsCollector<FieldValueHitQueue.Entry>
-
newTopDocs
protected TopDocs newTopDocs(ScoreDoc[] results, int start)
Description copied from class:TopDocsCollectorReturns aTopDocsinstance containing the given results. Ifresultsis 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:
newTopDocsin classTopDocsCollector<FieldValueHitQueue.Entry>
-
topDocs
public TopFieldDocs topDocs()
Description copied from class:TopDocsCollectorReturns the top docs that were collected by this collector.- Overrides:
topDocsin classTopDocsCollector<FieldValueHitQueue.Entry>
-
isEarlyTerminated
public boolean isEarlyTerminated()
Return whether collection terminated early.
-
-