Expert: a FieldComparator compares hits so as to determine their sort order when collecting the top results with {@link TopFieldCollector}. The concrete public FieldComparator classes here correspond to the SortField types.

This API is designed to achieve high performance sorting, by exposing a tight interaction with {@link FieldValueHitQueue} as it visits hits. Whenever a hit is competitive, it's enrolled into a virtual slot, which is an int ranging from 0 to numHits-1. The {@link FieldComparator} is made aware of segment transitions during searching in case any internal state it's tracking needs to be recomputed during these transitions.

A comparator must define these functions:

  • {@link #compare} Compare a hit at 'slot a' with hit 'slot b'.
  • {@link #setBottom} This method is called by {@link FieldValueHitQueue} to notify the FieldComparator of the current weakest ("bottom") slot. Note that this slot may not hold the weakest value according to your comparator, in cases where your comparator is not the primary one (ie, is only used to break ties from the comparators before it).
  • {@link #compareBottom} Compare a new hit (docID) against the "weakest" (bottom) entry in the queue.
  • {@link #copy} Installs a new hit into the priority queue. The {@link FieldValueHitQueue} calls this method when a new hit is competitive.
  • {@link #setNextReader} Invoked when the search is switching to the next segment. You may need to update internal state of the comparator, for example retrieving new values from the {@link FieldCache}.
  • {@link #value} Return the sort value stored in the specified slot. This is only called at the end of the search, in order to populate {@link FieldDoc#fields} when returning the top results.
NOTE: This API is experimental and might change in incompatible ways in the next release.

The FieldComparator..::..StringOrdValComparator type exposes the following members.

Constructors

  NameDescription
Public methodFieldComparator..::..StringOrdValComparator
Initializes a new instance of the FieldComparator..::..StringOrdValComparator class

Methods

  NameDescription
Public methodCompare (Overrides FieldComparator..::..Compare(Int32, Int32).)
Public methodCompareBottom (Overrides FieldComparator..::..CompareBottom(Int32).)
Public methodCopy (Overrides FieldComparator..::..Copy(Int32, Int32).)
Public methodEquals
Determines whether the specified Object is equal to the current Object.
(Inherited from Object.)
Protected methodFinalize
Allows an Object to attempt to free resources and perform other cleanup operations before the Object is reclaimed by garbage collection.
(Inherited from Object.)
Public methodGetBottomSlot
Public methodGetField
Public methodGetHashCode
Serves as a hash function for a particular type.
(Inherited from Object.)
Public methodGetType
Gets the Type of the current instance.
(Inherited from Object.)
Public methodGetValues
Protected methodMemberwiseClone
Creates a shallow copy of the current Object.
(Inherited from Object.)
Public methodSetBottom (Overrides FieldComparator..::..SetBottom(Int32).)
Public methodSetNextReader (Overrides FieldComparator..::..SetNextReader(IndexReader, Int32).)
Public methodSetScorer
Sets the Scorer to use in case a document's score is needed.
(Inherited from FieldComparator.)
Public methodToString
Returns a String that represents the current Object.
(Inherited from Object.)
Public methodValue (Overrides FieldComparator..::..Value(Int32).)

See Also