Class TopDocsCollector<T>
A base class for all collectors that return a TopDocs output. This collector allows easy extension by providing a single constructor which accepts a PriorityQueue<T> 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 to TopDocsCollector(PriorityQueue<T>). In that case
however, you might want to consider overriding all methods, in order to avoid
a
Inheritance
Assembly: DistributedLucene.Net.dll
Syntax
public abstract class TopDocsCollector<T> : object, ITopDocsCollector, ICollector where T : ScoreDoc
Type Parameters
Name | Description |
---|---|
T |
Constructors
Name | Description |
---|---|
TopDocsCollector(PriorityQueue<T>) | Sole constructor. |
Fields
Name | Description |
---|---|
EMPTY_TOPDOCS | This is used in case GetTopDocs() is called with illegal parameters, or there simply aren't (enough) results. |
m_pq | The priority queue which holds the top documents. Note that different implementations of PriorityQueue<T> give different meaning to 'top documents'. Lucene.Net.Search.HitQueue for example aggregates the top scoring documents, while other priority queue implementations may hold documents sorted by other criteria. |
m_totalHits | The total number of documents that the collector encountered. |
Properties
Name | Description |
---|---|
AcceptsDocsOutOfOrder | Return Most Lucene Query implementations will visit matching docIDs in order. However, some queries (currently limited to certain cases of BooleanQuery) can achieve faster searching if the ICollector allows them to deliver the docIDs out of order. Many collectors don't mind getting docIDs out of
order, so it's important to return |
TopDocsCount | The number of valid priority queue entries |
TotalHits | The total number of documents that matched this query. |
Methods
Name | Description |
---|---|
Collect(Int32) | Called once for every document matching a query, with the unbased document number. Note: The collection of the current segment can be terminated by throwing a CollectionTerminatedException. In this case, the last docs of the current AtomicReaderContext will be skipped and IndexSearcher will swallow the exception and continue collection with the next leaf.
Note: this is called in an inner search loop. For good search performance,
implementations of this method should not call |
GetTopDocs() | Returns the top docs that were collected by this collector. |
GetTopDocs(Int32) | Returns the documents in the rage [ 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
different |
GetTopDocs(Int32, Int32) | Returns the documents in the rage [
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 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 call GetTopDocs() and work with the returned TopDocs object, which will contain all the results this search execution collected. |
NewTopDocs(ScoreDoc[], Int32) | Returns a TopDocs instance containing the given results. If
|
PopulateResults(ScoreDoc[], Int32) | Populates the results array with the ScoreDoc instances. This can be overridden in case a different ScoreDoc type should be returned. |
SetNextReader(AtomicReaderContext) | Called before collecting from each AtomicReaderContext. All doc ids in Collect(Int32) will correspond to Reader. Add DocBase to the current Reader's internal document id to re-base ids in Collect(Int32). |
SetScorer(Scorer) | Called before successive calls to Collect(Int32). Implementations that need the score of the current document (passed-in to Collect(Int32)), should save the passed-in Scorer and call GetScore() when needed. |