public abstract class FieldComparator<T> extends Object
TopFieldCollector. The concrete public FieldComparator
classes here correspond to the SortField types.
The document IDs passed to these methods must only move forwards, since they are using doc values iterators to retrieve sort values.
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 int ranging from 0 to numHits-1. Segment transitions are
handled by creating a dedicated per-segment
LeafFieldComparator which also needs to interact
FieldValueHitQueue but can optimize based
on the segment to collect.
The following functions need to be implemented
compare(int, int) Compare a hit at 'slot a'
with hit 'slot b'.
setTopValue(T) This method is called by
TopFieldCollector to notify the
FieldComparator of the top most value, which is
used by future calls to
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
value(int) Return the sort value stored in
the specified slot. This is only called at the end
of the search, in order to populate
FieldDoc.fields when returning the top results.
|Modifier and Type
|Class and Description
Sorts by descending relevance.
Sorts by field's natural Term sort order, using ordinals.
Sorts by field's natural Term sort order.
|Constructor and Description
|Modifier and Type
|Method and Description
Compare hit at slot1 with hit at slot2.
Returns a negative integer if first is less than second, 0 if they are equal and a positive integer otherwise.
Informs the comparator that the skipping of documents should be disabled.
Informs the comparator that sort is done on this single field.
Record the top value, for future calls to
Return the actual value in the slot.
public abstract int compare(int slot1, int slot2)
slot1 - first slot to compare
slot2 - second slot to compare
N < 0 if slot2's value is sorted after
N > 0 if the slot2's value is sorted before
0 if they are equal
public abstract void setTopValue(T value)
public abstract T value(int slot)
slot - the value
public abstract LeafFieldComparator getLeafComparator(LeafReaderContext context) throws IOException
LeafFieldComparator to collect the given
LeafReaderContext. All docIDs supplied to
LeafFieldComparator are relative to the current reader (you
must add docBase if you need to map it to a top-level docID).
context - current reader context
IOException - if there is a low-level IO error
public void setSingleSort()
public void disableSkipping()
Copyright © 2000-2021 Apache Software Foundation. All Rights Reserved.