Class SortField
- Direct Known Subclasses:
SortedNumericSortField,SortedSetSortField
Sorting on a numeric field that is indexed with both doc values and points may use an optimization to skip non-competitive documents. This optimization relies on the assumption that the same data is stored in these points and doc values.
Sorting on a SORTED(_SET) field that is indexed with both doc values and term index may use an optimization to skip non-competitive documents. This optimization relies on the assumption that the same data is stored in these term index and doc values.
Created: Feb 11, 2004 1:25:29 PM
- Since:
- lucene 1.4
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final classA SortFieldProvider for field sortsstatic enumSpecifies the type of the terms to be sorted, or special types such as CUSTOM -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final SortFieldRepresents sorting by document number (index order).static final SortFieldRepresents sorting by document score (relevance).protected Objectstatic final ObjectPass this tosetMissingValue(java.lang.Object)to have missing string values sort first.static final ObjectPass this tosetMissingValue(java.lang.Object)to have missing string values sort last. -
Constructor Summary
ConstructorsConstructorDescriptionSortField(String field, FieldComparatorSource comparator) Creates a sort with a custom comparison function.SortField(String field, FieldComparatorSource comparator, boolean reverse) Creates a sort, possibly in reverse, with a custom comparison function.SortField(String field, SortField.Type type) Creates a sort by terms in the given field with the type of term values explicitly given.SortField(String field, SortField.Type type, boolean reverse) Creates a sort, possibly in reverse, by terms in the given field with the type of term values explicitly given. -
Method Summary
Modifier and TypeMethodDescriptionbooleanReturns true ifois equal to this.getComparator(int numHits, Pruning pruning) Returns theFieldComparatorto use for sorting.Returns theFieldComparatorSourceused for custom sortinggetField()Returns the name of the field.Returns anIndexSorterused for sorting index segments by this SortField.Return the value to use for documents that don't have a value.booleanDeprecated.booleanDeprecated.booleanReturns whether the sort should be reversed.getType()Returns the type of contents in the field.inthashCode()Returns a hash code for thisSortFieldinstance.booleanWhether the relevance score is needed to sort documents.protected static SortField.Typerewrite(IndexSearcher searcher) Rewrites this SortField, returning a new SortField if a change is made.voidvoidsetMissingValue(Object missingValue) Set the value to use for documents that don't have a value.voidsetOptimizeSortWithIndexedData(boolean optimizeSortWithIndexedData) Deprecated.should only be used for compatibility with 8.x indices that got created with inconsistent data across fields, or the wrong sort configuration in the index sortvoidsetOptimizeSortWithPoints(boolean optimizeSortWithPoints) Deprecated.should only be used for compatibility with 8.x indices that got created with inconsistent data across fields, or the wrong sort configuration in the index sort.toString()
-
Field Details
-
FIELD_SCORE
Represents sorting by document score (relevance). -
FIELD_DOC
Represents sorting by document number (index order). -
missingValue
-
STRING_FIRST
Pass this tosetMissingValue(java.lang.Object)to have missing string values sort first. -
STRING_LAST
Pass this tosetMissingValue(java.lang.Object)to have missing string values sort last.
-
-
Constructor Details
-
SortField
Creates a sort by terms in the given field with the type of term values explicitly given.- Parameters:
field- Name of field to sort by. Can benulliftypeis SCORE or DOC.type- Type of values in the terms.
-
SortField
Creates a sort, possibly in reverse, by terms in the given field with the type of term values explicitly given.- Parameters:
field- Name of field to sort by. Can benulliftypeis SCORE or DOC.type- Type of values in the terms.reverse- True if natural order should be reversed.
-
SortField
Creates a sort with a custom comparison function.- Parameters:
field- Name of field to sort by; cannot benull.comparator- Returns a comparator for sorting hits.
-
SortField
Creates a sort, possibly in reverse, with a custom comparison function.- Parameters:
field- Name of field to sort by; cannot benull.comparator- Returns a comparator for sorting hits.reverse- True if natural order should be reversed.
-
-
Method Details
-
readType
- Throws:
IOException
-
getMissingValue
Return the value to use for documents that don't have a value. A value ofnullindicates that default should be used. -
setMissingValue
Set the value to use for documents that don't have a value. -
getField
Returns the name of the field. Could returnnullif the sort is by SCORE or DOC.- Returns:
- Name of field, possibly
null.
-
getType
Returns the type of contents in the field.- Returns:
- One of the constants SCORE, DOC, STRING, INT or FLOAT.
-
getReverse
public boolean getReverse()Returns whether the sort should be reversed.- Returns:
- True if natural order should be reversed.
-
getComparatorSource
Returns theFieldComparatorSourceused for custom sorting -
toString
-
equals
Returns true ifois equal to this. If aFieldComparatorSourcewas provided, it must properly implement equals (unless a singleton is always used). -
hashCode
public int hashCode()Returns a hash code for thisSortFieldinstance. If aFieldComparatorSourcewas provided, it must properly implement hashCode (unless a singleton is always used). -
setBytesComparator
-
getBytesComparator
-
getComparator
Returns theFieldComparatorto use for sorting.- 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- WARNING: This API is experimental and might change in incompatible ways in the next release.
-
rewrite
Rewrites this SortField, returning a new SortField if a change is made. Subclasses should override this define their rewriting behavior when this SortField is of typeSortField.Type.REWRITEABLE- Parameters:
searcher- IndexSearcher to use during rewriting- Returns:
- New rewritten SortField, or
thisif nothing has changed. - Throws:
IOException- Can be thrown by the rewriting- WARNING: This API is experimental and might change in incompatible ways in the next release.
-
needsScores
public boolean needsScores()Whether the relevance score is needed to sort documents. -
getIndexSorter
Returns 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- WARNING: This API is experimental and might change in incompatible ways in the next release.
-
setOptimizeSortWithIndexedData
Deprecated.should only be used for compatibility with 8.x indices that got created with inconsistent data across fields, or the wrong sort configuration in the index sortEnables/disables numeric sort optimization to use the indexed data.Enabled by default. By default, sorting on a numeric field activates point sort optimization that can efficiently skip over non-competitive hits. Sort optimization has a number of requirements, one of which is that SortField.Type matches the Point type with which the field was indexed (e.g. sort on IntPoint field should use SortField.Type.INT). Another requirement is that the same data is indexed with points and doc values for the field.
By default, sorting on a SORTED(_SET) field activates sort optimization that can efficiently skip over non-competitive hits. Sort optimization requires that the same data is indexed with term index and doc values for the field.
- Parameters:
optimizeSortWithIndexedData- providingfalsedisables the optimization, in cases where these requirements can't be met.
-
getOptimizeSortWithIndexedData
Deprecated.Returns whether sort optimization should be optimized with indexed data- Returns:
- whether sort optimization should be optimized with indexed data
-
setOptimizeSortWithPoints
Deprecated.should only be used for compatibility with 8.x indices that got created with inconsistent data across fields, or the wrong sort configuration in the index sort. This is a duplicate method forSortField#setOptimizeSortWithIndexedData.Enables/disables numeric sort optimization to use the Points index.Enabled by default. By default, sorting on a numeric field activates point sort optimization that can efficiently skip over non-competitive hits. Sort optimization has a number of requirements, one of which is that SortField.Type matches the Point type with which the field was indexed (e.g. sort on IntPoint field should use SortField.Type.INT). Another requirement is that the same data is indexed with points and doc values for the field.
- Parameters:
optimizeSortWithPoints- providingfalsedisables the optimization, in cases where these requirements can't be met.
-
getOptimizeSortWithPoints
Deprecated.This is a duplicate method forSortField#getOptimizeSortWithIndexedData.Returns whether sort optimization should be optimized with points index- Returns:
- whether sort optimization should be optimized with points index
-
SortField#getOptimizeSortWithIndexedData.