Class FieldComparer<T>
Expert: a FieldComparer compares hits so as to determine their sort order when collecting the top results with TopFieldCollector. The concrete public FieldComparer classes here correspond to the SortField types.
This API is designed to achieve high performance
sorting, by exposing a tight interaction with
FieldValueHitQueue as it visits hits. Whenever a hit is
competitive, it's enrolled into a virtual slot, which is
an
A comparer must define these functions:
- Compare(Int32, Int32) Compare a hit at 'slot a' with hit 'slot b'.
- SetBottom(Int32)This method is called by FieldValueHitQueue to notify the FieldComparer of the current weakest ("bottom") slot. Note that this slot may not hold the weakest value according to your comparer, in cases where your comparer is not the primary one (ie, is only used to break ties from the comparers before it).
- CompareBottom(Int32)Compare a new hit (docID) against the "weakest" (bottom) entry in the queue.
- SetTopValue(Object)This method is called by TopFieldCollector to notify the FieldComparer of the top most value, which is used by future calls to CompareTop(Int32).
- CompareTop(Int32)Compare a new hit (docID) against the top value previously set by a call to SetTopValue(Object).
- Copy(Int32, Int32)Installs a new hit into the priority queue. The FieldValueHitQueue calls this method when a new hit is competitive.
- SetNextReader(AtomicReaderContext)Invoked when the search is switching to the next segment. You may need to update internal state of the comparer, for example retrieving new values from the IFieldCache.
- Item[Int32]Return the sort value stored in the specified slot. This is only called at the end of the search, in order to populate Fields when returning the top results.
@lucene.experimental
Assembly: DistributedLucene.Net.dll
Syntax
public abstract class FieldComparer<T> : FieldComparer
Type Parameters
Name | Description |
---|---|
T |
Methods
Name | Description |
---|---|
Compare(Int32, Int32) | Compare hit at |
CompareBottom(Int32) | Compare the bottom of the queue with this doc. This will only invoked after SetBottom(Int32) has been called. This should return the same result as Compare(Int32, Int32) as if bottom were slot1 and the new document were slot 2. For a search that hits many results, this method will be the hotspot (invoked by far the most frequently). |
CompareTop(Int32) | Compare the top value with this doc. This will only invoked after SetTopValue(Object) has been called. This should return the same result as Compare(Int32, Int32) as if topValue were slot1 and the new document were slot 2. This is only called for searches that use SearchAfter (deep paging). |
CompareValues(T, T) | Returns -1 if first is less than second. Default
impl to assume the type implements |
CompareValues(Object, Object) | Returns -1 if first is less than second. Default
impl to assume the type implements |
Copy(Int32, Int32) | This method is called when a new hit is competitive. You should copy any state associated with this document that will be required for future comparisons, into the specified slot. |
SetBottom(Int32) | Set the bottom slot, ie the "weakest" (sorted last) entry in the queue. When CompareBottom(Int32) is called, you should compare against this slot. This will always be called before CompareBottom(Int32). |
SetNextReader(AtomicReaderContext) | Set a new AtomicReaderContext. All subsequent docIDs are relative to the current reader (you must add docBase if you need to map it to a top-level docID). |
SetTopValue(Object) | Record the top value, for future calls to CompareTop(Int32). This is only called for searches that use SearchAfter (deep paging), and is called before any calls to SetNextReader(AtomicReaderContext). |