Class EarlyTerminatingSortingCollector
A Lucene.Net.Search.ICollector that early terminates collection of documents on a per-segment basis, if the segment was sorted according to the given Lucene.Net.Search.Sort.
NOTE: the Lucene.Net.Search.ICollector detects sorted segments according to SortingMergePolicy, so it's best used in conjunction with it. Also, it collects up to a specified m_numDocsToCollect from each segment, and therefore is mostly suitable for use in conjunction with collectors such as Lucene.Net.Search.TopDocsCollector<T>, and not e.g. Lucene.Net.Search.TotalHitCountCollector.
NOTE: If you wrap a Lucene.Net.Search.TopDocsCollector<T> that sorts in the same order as the index order, the returned TopDocs will be correct. However the total of Lucene.Net.Search.TopDocsCollector<T>.TotalHits hit count will be underestimated since not all matching documents will have been collected.
NOTE: This Lucene.Net.Search.ICollector uses Lucene.Net.Search.Sort.ToString() to detect whether a segment was sorted with the same Lucene.Net.Search.Sort. This has two implications:
- if a custom comparer is not implemented correctly and returns different identifiers for equivalent instances, this collector will not detect sorted segments,
- if you suddenly change the Lucene.Net.Index.IndexWriter's SortingMergePolicy to sort according to another criterion and if both the old and the new Lucene.Net.Search.Sorts have the same identifier, this Lucene.Net.Search.ICollector will incorrectly detect sorted segments.
Note
This API is experimental and might change in incompatible ways in the next release.
Implements
Inherited Members
Namespace: Lucene.Net.Index.Sorter
Assembly: Lucene.Net.Misc.dll
Syntax
public class EarlyTerminatingSortingCollector : ICollector
Constructors
EarlyTerminatingSortingCollector(ICollector, Sort, int)
Create a new EarlyTerminatingSortingCollector instance.
Declaration
public EarlyTerminatingSortingCollector(ICollector @in, Sort sort, int numDocsToCollect)
Parameters
Type | Name | Description |
---|---|---|
ICollector | in | the collector to wrap |
Sort | sort | the sort you are sorting the search results on |
int | numDocsToCollect | the number of documents to collect on each segment. When wrapping a Lucene.Net.Search.TopDocsCollector<T>, this number should be the number of hits. |
Fields
m_in
The wrapped Collector
Declaration
protected readonly ICollector m_in
Field Value
Type | Description |
---|---|
ICollector |
m_numDocsToCollect
Number of documents to collect in each segment
Declaration
protected readonly int m_numDocsToCollect
Field Value
Type | Description |
---|---|
int |
m_segmentSorted
True if the current segment being processed is sorted by Lucene.Net.Search.Sort.Sort()
Declaration
protected bool m_segmentSorted
Field Value
Type | Description |
---|---|
bool |
m_segmentTotalCollect
Number of documents to collect in the current segment being processed
Declaration
protected int m_segmentTotalCollect
Field Value
Type | Description |
---|---|
int |
m_sort
Sort used to sort the search results
Declaration
protected readonly Sort m_sort
Field Value
Type | Description |
---|---|
Sort |
Properties
AcceptsDocsOutOfOrder
Return true
if this collector does not
require the matching docIDs to be delivered in int sort
order (smallest to largest) to Collect(int).
Most Lucene Query implementations will visit matching docIDs in order. However, some queries (currently limited to certain cases of Lucene.Net.Search.BooleanQuery) can achieve faster searching if the Lucene.Net.Search.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 true
here.
Declaration
public virtual bool AcceptsDocsOutOfOrder { get; }
Property Value
Type | Description |
---|---|
bool |
Methods
Collect(int)
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 Lucene.Net.Search.CollectionTerminatedException. In this case, the last docs of the current Lucene.Net.Index.AtomicReaderContext will be skipped and Lucene.Net.Search.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 Doc(int) or Document(int) on every hit. Doing so can slow searches by an order of magnitude or more.Declaration
public virtual void Collect(int doc)
Parameters
Type | Name | Description |
---|---|---|
int | doc |
SetNextReader(AtomicReaderContext)
Called before collecting from each Lucene.Net.Index.AtomicReaderContext. All doc ids in Collect(int) will correspond to Lucene.Net.Index.IndexReaderContext.Reader.
Add Lucene.Net.Index.AtomicReaderContext.DocBase to the current Lucene.Net.Index.IndexReaderContext.Reader's internal document id to re-base ids in Collect(int).Declaration
public virtual void SetNextReader(AtomicReaderContext context)
Parameters
Type | Name | Description |
---|---|---|
AtomicReaderContext | context | next atomic reader context |
SetScorer(Scorer)
Called before successive calls to Collect(int). Implementations
that need the score of the current document (passed-in to
Collect(int)), should save the passed-in Lucene.Net.Search.Scorer and call
scorer.GetScore()
when needed.
Declaration
public virtual void SetScorer(Scorer scorer)
Parameters
Type | Name | Description |
---|---|---|
Scorer | scorer |