Module org.apache.lucene.core
Class NumericComparator.NumericLeafComparator
- java.lang.Object
-
- org.apache.lucene.search.comparators.NumericComparator.NumericLeafComparator
-
- All Implemented Interfaces:
LeafFieldComparator
- Direct Known Subclasses:
DoubleComparator.DoubleLeafComparator
,FloatComparator.FloatLeafComparator
,IntComparator.IntLeafComparator
,LongComparator.LongLeafComparator
- Enclosing class:
- NumericComparator<T extends java.lang.Number>
public abstract class NumericComparator.NumericLeafComparator extends java.lang.Object implements LeafFieldComparator
Leaf comparator forNumericComparator
that provides skipping functionality
-
-
Field Summary
Fields Modifier and Type Field Description private DocIdSetIterator
competitiveIterator
private LeafReaderContext
context
private int
currentSkipInterval
protected NumericDocValues
docValues
private boolean
enableSkipping
private long
iteratorCost
private int
maxDoc
private int
maxDocVisited
private byte[]
maxValueAsBytes
private byte[]
minValueAsBytes
private PointValues.PointTree
pointTree
private PointValues
pointValues
private int
tryUpdateFailCount
private int
updateCounter
-
Constructor Summary
Constructors Constructor Description NumericLeafComparator(LeafReaderContext context)
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected abstract int
compareMissingValueWithBottomValue()
protected abstract int
compareMissingValueWithTopValue()
in ascending sort, missing value is competitive when it is less or equal(maybe there are two or more comparators) than bottom value.DocIdSetIterator
competitiveIterator()
Returns a competitive iteratorvoid
copy(int slot, int doc)
This method is called when a new hit is competitive.private void
encodeBottom()
IfNumericComparator.pruning
equalsPruning.GREATER_THAN_OR_EQUAL_TO
, we could better tune themaxValueAsBytes
/minValueAsBytes
.protected abstract void
encodeBottom(byte[] packedValue)
private void
encodeTop()
IfNumericComparator.pruning
equalsPruning.GREATER_THAN_OR_EQUAL_TO
, we could better tune themaxValueAsBytes
/minValueAsBytes
.protected abstract void
encodeTop(byte[] packedValue)
protected NumericDocValues
getNumericDocValues(LeafReaderContext context, java.lang.String field)
Retrieves the NumericDocValues for the field in this segmentprivate PointValues.PointTree
getPointTree()
private boolean
isMissingValueCompetitive()
void
setBottom(int slot)
Set the bottom slot, ie the "weakest" (sorted last) entry in the queue.void
setHitsThresholdReached()
Informs this leaf comparator that hits threshold is reached.void
setScorer(Scorable scorer)
Sets the Scorer to use in case a document's score is needed.private void
updateCompetitiveIterator()
private void
updateSkipInterval(boolean success)
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.apache.lucene.search.LeafFieldComparator
compareBottom, compareTop
-
-
-
-
Field Detail
-
context
private final LeafReaderContext context
-
docValues
protected final NumericDocValues docValues
-
pointValues
private final PointValues pointValues
-
pointTree
private PointValues.PointTree pointTree
-
enableSkipping
private final boolean enableSkipping
-
maxDoc
private final int maxDoc
-
minValueAsBytes
private byte[] minValueAsBytes
-
maxValueAsBytes
private byte[] maxValueAsBytes
-
competitiveIterator
private DocIdSetIterator competitiveIterator
-
iteratorCost
private long iteratorCost
-
maxDocVisited
private int maxDocVisited
-
updateCounter
private int updateCounter
-
currentSkipInterval
private int currentSkipInterval
-
tryUpdateFailCount
private int tryUpdateFailCount
-
-
Constructor Detail
-
NumericLeafComparator
public NumericLeafComparator(LeafReaderContext context) throws java.io.IOException
- Throws:
java.io.IOException
-
-
Method Detail
-
getNumericDocValues
protected NumericDocValues getNumericDocValues(LeafReaderContext context, java.lang.String field) throws java.io.IOException
Retrieves the NumericDocValues for the field in this segmentIf you override this method, you should probably always disable skipping as the comparator uses values from the points index to build its competitive iterators, and assumes that the values in doc values and points are the same.
- Parameters:
context
- – reader contextfield
- - field name- Returns:
- numeric doc values for the field in this segment.
- Throws:
java.io.IOException
- If there is a low-level I/O error
-
setBottom
public void setBottom(int slot) throws java.io.IOException
Description copied from interface:LeafFieldComparator
Set the bottom slot, ie the "weakest" (sorted last) entry in the queue. WhenLeafFieldComparator.compareBottom(int)
is called, you should compare against this slot. This will always be called beforeLeafFieldComparator.compareBottom(int)
.- Specified by:
setBottom
in interfaceLeafFieldComparator
- Parameters:
slot
- the currently weakest (sorted last) slot in the queue- Throws:
java.io.IOException
-
copy
public void copy(int slot, int doc) throws java.io.IOException
Description copied from interface:LeafFieldComparator
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.- Specified by:
copy
in interfaceLeafFieldComparator
- Parameters:
slot
- which slot to copy the hit todoc
- docID relative to current reader- Throws:
java.io.IOException
-
setScorer
public void setScorer(Scorable scorer) throws java.io.IOException
Description copied from interface:LeafFieldComparator
Sets the Scorer to use in case a document's score is needed.- Specified by:
setScorer
in interfaceLeafFieldComparator
- Parameters:
scorer
- Scorer instance that you should use to obtain the current hit's score, if necessary.- Throws:
java.io.IOException
-
setHitsThresholdReached
public void setHitsThresholdReached() throws java.io.IOException
Description copied from interface:LeafFieldComparator
Informs this leaf comparator that hits threshold is reached. This method is called from a collector when hits threshold is reached.- Specified by:
setHitsThresholdReached
in interfaceLeafFieldComparator
- Throws:
java.io.IOException
-
updateCompetitiveIterator
private void updateCompetitiveIterator() throws java.io.IOException
- Throws:
java.io.IOException
-
getPointTree
private PointValues.PointTree getPointTree() throws java.io.IOException
- Throws:
java.io.IOException
-
updateSkipInterval
private void updateSkipInterval(boolean success)
-
encodeBottom
private void encodeBottom()
IfNumericComparator.pruning
equalsPruning.GREATER_THAN_OR_EQUAL_TO
, we could better tune themaxValueAsBytes
/minValueAsBytes
. For instance, if the sort is ascending and bottom value is 5, we will use a range on [MIN_VALUE, 4].
-
encodeTop
private void encodeTop()
IfNumericComparator.pruning
equalsPruning.GREATER_THAN_OR_EQUAL_TO
, we could better tune themaxValueAsBytes
/minValueAsBytes
. For instance, if the sort is ascending and top value is 3, we will use a range on [4, MAX_VALUE].
-
isMissingValueCompetitive
private boolean isMissingValueCompetitive()
-
competitiveIterator
public DocIdSetIterator competitiveIterator()
Description copied from interface:LeafFieldComparator
Returns a competitive iterator- Specified by:
competitiveIterator
in interfaceLeafFieldComparator
- Returns:
- an iterator over competitive docs that are stronger than already collected docs or
null
if such an iterator is not available for the current comparator or segment.
-
compareMissingValueWithTopValue
protected abstract int compareMissingValueWithTopValue()
in ascending sort, missing value is competitive when it is less or equal(maybe there are two or more comparators) than bottom value. if there is only one comparator(SeePruning.GREATER_THAN_OR_EQUAL_TO
), missing value is competitive only when it is less than bottom value. vice versa in descending sort.
-
compareMissingValueWithBottomValue
protected abstract int compareMissingValueWithBottomValue()
-
encodeBottom
protected abstract void encodeBottom(byte[] packedValue)
-
encodeTop
protected abstract void encodeTop(byte[] packedValue)
-
-