Class BinarySortField
BinaryDocValues, usable as an index sort.
Unlike a SortField.Type.STRING sort (backed by SortedDocValues), values are compared directly rather
than through a term dictionary, making this a good fit for high-cardinality fields where a
dictionary would be pure overhead. Documents are ordered by the unsigned byte order of their sort
key (BytesRef.compareTo(org.apache.lucene.util.BytesRef)), optionally reversed, with missing values sorted first or last
via SortField.STRING_FIRST / SortField.STRING_LAST (first by default).
By default the sort key is the stored value. A subclass may override getSortKeyDocValues(LeafReader) to derive an order-preserving key from the stored bytes and/or
other doc-values fields of the segment (for example to select the minimum of a multi-valued
field). Such a subclass must register a SortFieldProvider via SPI so the sort can be read
back and used on merge.
This field can also sort search results, comparing values with a linear scan of the binary doc
values (without the skipping optimizations available to numeric or SORTED fields).
- WARNING: This API is experimental and might change in incompatible ways in the next release.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final classA SortFieldProvider for this sortNested classes/interfaces inherited from class org.apache.lucene.search.SortField
SortField.Type -
Field Summary
Fields inherited from class org.apache.lucene.search.SortField
FIELD_DOC, FIELD_SCORE, missingValue, reverse, STRING_FIRST, STRING_LAST -
Constructor Summary
ConstructorsModifierConstructorDescriptionBinarySortField(String field, boolean reverse) Creates a sort, possibly in reverse, by the unsigned byte order of the field's value.BinarySortField(String field, boolean reverse, Object missingValue) Creates a sort, possibly in reverse, by the unsigned byte order of the field's value, with the given handling of missing values.protectedBinarySortField(String field, boolean reverse, Object missingValue, String providerName) Creates a sort for a subclass that overridesgetSortKeyDocValues(LeafReader). -
Method Summary
Modifier and TypeMethodDescriptionbooleanReturns true ifois equal to this.getComparator(int numHits, Pruning pruning) Returns theFieldComparatorto use for sorting.Returns anIndexSorterused for sorting index segments by this SortField.protected BinaryDocValuesgetSortKeyDocValues(LeafReader reader) Returns the per-document sort key, as aBinaryDocValueswhoseBinaryDocValues.binaryValue()is the bytes to sort on.inthashCode()Returns a hash code for thisSortFieldinstance.toString()Methods inherited from class org.apache.lucene.search.SortField
getComparatorSource, getField, getMissingValue, getOptimizeSortWithIndexedData, getOptimizeSortWithPoints, getReverse, getType, needsScores, readType, rewrite, setMissingValue, setOptimizeSortWithIndexedData, setOptimizeSortWithPoints
-
Constructor Details
-
BinarySortField
Creates a sort, possibly in reverse, by the unsigned byte order of the field's value.- Parameters:
field- Name of field to sort by. Must not be null.reverse- True if natural order should be reversed.
-
BinarySortField
Creates a sort, possibly in reverse, by the unsigned byte order of the field's value, with the given handling of missing values.- Parameters:
field- Name of field to sort by. Must not be null.reverse- True if natural order should be reversed.missingValue-SortField.STRING_FIRST,SortField.STRING_LAST, ornull(missing first).
-
BinarySortField
Creates a sort for a subclass that overridesgetSortKeyDocValues(LeafReader).The subclass must supply the name of a dedicated
SortFieldProvider(registered via SPI) whoseSortFieldProvider.readSortField(org.apache.lucene.store.DataInput)reconstructs the subclass, so that the same sort-key derivation is used when the index sort is read back and on merge.- Parameters:
field- Name of field to sort by. Must not be null.reverse- True if natural order should be reversed.missingValue-SortField.STRING_FIRST,SortField.STRING_LAST, ornull.providerName- the SPI name of the companionSortFieldProvider.
-
-
Method Details
-
getSortKeyDocValues
Returns the per-document sort key, as aBinaryDocValueswhoseBinaryDocValues.binaryValue()is the bytes to sort on. The default returns the field's values unchanged; override to derive a key from the stored bytes and/or other doc-values fields of the segment.Values are read in increasing docID order; advance any underlying doc values with
DocIdSetIterator.nextDoc()only, since at flush time the in-memory doc values do not supportadvanceExact. The returned key has the same lifetime asBinaryDocValues.binaryValue()(valid until the next call) and need not be a copy.- Throws:
IOException
-
getIndexSorter
Description copied from class:SortFieldReturns anIndexSorterused for sorting index segments by this SortField.If the SortField cannot be used for index sorting (for example, if it uses scores or other query-dependent values) then this method should return
nullSortFields that implement this method should also implement a companion
SortFieldProviderto serialize and deserialize the sort in index segment headers- Overrides:
getIndexSorterin classSortField
-
getComparator
Description copied from class:SortFieldReturns theFieldComparatorto use for sorting.- Overrides:
getComparatorin classSortField- Parameters:
numHits- number of top hits the queue will storepruning- controls how can the comparator to skip documents viaLeafFieldComparator.competitiveIterator()- Returns:
FieldComparatorto use when sorting
-
hashCode
public int hashCode()Description copied from class:SortFieldReturns a hash code for thisSortFieldinstance. If aFieldComparatorSourcewas provided, it must properly implement hashCode (unless a singleton is always used). -
equals
Description copied from class:SortFieldReturns true ifois equal to this. If aFieldComparatorSourcewas provided, it must properly implement equals (unless a singleton is always used). -
toString
-