Package org.apache.lucene.search
Class SortedSetSortField
java.lang.Object
org.apache.lucene.search.SortField
org.apache.lucene.search.SortedSetSortField
SortField for
SortedSetDocValues.
A SortedSetDocValues contains multiple values for a field, so sorting with this technique "selects" a value as the representative sort value for the document.
By default, the minimum value in the set is selected as the sort value, but this can be customized. Selectors other than the default do have some limitations to ensure that all selections happen in constant-time for performance.
Like sorting by string, this also supports sorting missing values as first or last,
via setMissingValue(Object).
- See Also:
-
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
FieldsFields inherited from class org.apache.lucene.search.SortField
FIELD_DOC, FIELD_SCORE, missingValue, reverse, STRING_FIRST, STRING_LAST -
Constructor Summary
ConstructorsConstructorDescriptionSortedSetSortField(String field, boolean reverse) Creates a sort, possibly in reverse, by the minimum value in the set for the document.SortedSetSortField(String field, boolean reverse, SortedSetSelector.Type selector) Creates a sort, possibly in reverse, specifying how the sort value from the document's set is selected. -
Method Summary
Modifier and TypeMethodDescriptionbooleanReturns true ifois equal to this.getComparator(int numHits, int sortPos) Returns theFieldComparatorto use for sorting.Returns anIndexSorterused for sorting index segments by this SortField.Returns the selector in use for this sortprivate SortedDocValuesgetValues(LeafReader reader) inthashCode()Returns a hash code for thisSortFieldinstance.private static SortedSetSelector.Typeprivate voidserialize(DataOutput out) voidsetMissingValue(Object missingValue) Set how missing values (the empty set) are sorted.toString()Methods inherited from class org.apache.lucene.search.SortField
getBytesComparator, getCanUsePoints, getComparatorSource, getField, getMissingValue, getReverse, getType, needsScores, readType, rewrite, setBytesComparator, setCanUsePoints
-
Field Details
-
selector
-
-
Constructor Details
-
SortedSetSortField
Creates a sort, possibly in reverse, by the minimum value in the set for the document.- Parameters:
field- Name of field to sort by. Must not be null.reverse- True if natural order should be reversed.
-
SortedSetSortField
Creates a sort, possibly in reverse, specifying how the sort value from the document's set is selected.- Parameters:
field- Name of field to sort by. Must not be null.reverse- True if natural order should be reversed.selector- custom selector type for choosing the sort value from the set.NOTE: selectors other than
SortedSetSelector.Type.MINrequire optional codec support.
-
-
Method Details
-
readSelectorType
- Throws:
IOException
-
serialize
- Throws:
IOException
-
getSelector
Returns the selector in use for this sort -
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).canUsePointsfield is not part ofequalsandhasCodeintentionally, as it is only useful during search-time and using it in these functions prevents index sorting optimizations that rely on the equality of the index-time and search-time SortField instances. -
toString
-
setMissingValue
Set how missing values (the empty set) are sorted.Note that this must be
SortField.STRING_FIRSTorSortField.STRING_LAST.- Overrides:
setMissingValuein classSortField
-
getComparator
Description copied from class:SortFieldReturns theFieldComparatorto use for sorting.- Overrides:
getComparatorin classSortField- Parameters:
numHits- number of top hits the queue will storesortPos- position of this SortField withinSort. The comparator is primary if sortPos==0, secondary if sortPos==1, etc. Some comparators can optimize themselves when they are the primary sort.- Returns:
FieldComparatorto use when sorting
-
getValues
- 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 returnnullSortFields that implement this method should also implement a companionSortFieldProviderto serialize and deserialize the sort in index segment headers- Overrides:
getIndexSorterin classSortField
-