Package org.apache.lucene.search
Class TopDocsCollector<T extends ScoreDoc>
- java.lang.Object
-
- org.apache.lucene.search.Collector
-
- org.apache.lucene.search.TopDocsCollector<T>
-
- Direct Known Subclasses:
TopFieldCollector
,TopScoreDocCollector
public abstract class TopDocsCollector<T extends ScoreDoc> extends Collector
A base class for all collectors that return aTopDocs
output. This collector allows easy extension by providing a single constructor which accepts aPriorityQueue
as well as protected members for that priority queue and a counter of the number of total hits.
Extending classes can override any of the methods to provide their own implementation, as well as avoid the use of the priority queue entirely by passing null toTopDocsCollector(PriorityQueue)
. In that case however, you might want to consider overriding all methods, in order to avoid a NullPointerException.
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description int
getTotalHits()
The total number of documents that matched this query.TopDocs
topDocs()
Returns the top docs that were collected by this collector.TopDocs
topDocs(int start)
Returns the documents in the rage [start ..TopDocs
topDocs(int start, int howMany)
Returns the documents in the rage [start ..-
Methods inherited from class org.apache.lucene.search.Collector
acceptsDocsOutOfOrder, collect, setNextReader, setScorer
-
-
-
-
Method Detail
-
getTotalHits
public int getTotalHits()
The total number of documents that matched this query.
-
topDocs
public TopDocs topDocs()
Returns the top docs that were collected by this collector.
-
topDocs
public TopDocs topDocs(int start)
Returns the documents in the rage [start .. pq.size()) that were collected by this collector. Note that if start >= pq.size(), an empty TopDocs is returned.
This method is convenient to call if the application always asks for the last results, starting from the last 'page'.
NOTE: you cannot call this method more than once for each search execution. If you need to call it more than once, passing each time a differentstart
, you should calltopDocs()
and work with the returnedTopDocs
object, which will contain all the results this search execution collected.
-
topDocs
public TopDocs topDocs(int start, int howMany)
Returns the documents in the rage [start .. start+howMany) that were collected by this collector. Note that if start >= pq.size(), an empty TopDocs is returned, and if pq.size() - start < howMany, then only the available documents in [start .. pq.size()) are returned.
This method is useful to call in case pagination of search results is allowed by the search application, as well as it attempts to optimize the memory used by allocating only as much as requested by howMany.
NOTE: you cannot call this method more than once for each search execution. If you need to call it more than once, passing each time a different range, you should calltopDocs()
and work with the returnedTopDocs
object, which will contain all the results this search execution collected.
-
-