Package org.apache.lucene.search
Class SortField
java.lang.Object
org.apache.lucene.search.SortField
Stores information about how to sort documents by terms in an individual
field. Fields must be indexed in order to sort by them.
Created: Feb 11, 2004 1:25:29 PM
- Since:
- lucene 1.4
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic 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).booleanstatic 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, FieldCache.Parser parser) Creates a sort by terms in the given field, parsed to numeric values using a customFieldCache.Parser.SortField(String field, FieldCache.Parser parser, boolean reverse) Creates a sort, possibly in reverse, by terms in the given field, parsed to numeric values using a customFieldCache.Parser.SortField(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, int sortPos) Returns theFieldComparatorto use for sorting.Returns theFieldComparatorSourceused for custom sortinggetField()Returns the name of the field.Returns the instance of aFieldCacheparser that fits to the given sort type.booleanReturns whether the sort should be reversed.getType()Returns the type of contents in the field.inthashCode()Returns true ifois equal to this.booleanWhether the relevance score is needed to sort documents.rewrite(IndexSearcher searcher) Rewrites this SortField, returning a new SortField if a change is made.voidvoidsetMissingValue(Object missingValue) toString()
-
Field Details
-
FIELD_SCORE
Represents sorting by document score (relevance). -
FIELD_DOC
Represents sorting by document number (index order). -
missingValue
-
sortMissingLast
public boolean sortMissingLast -
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 by terms in the given field, parsed to numeric values using a customFieldCache.Parser.- Parameters:
field- Name of field to sort by. Must not be null.parser- Instance of aFieldCache.Parser, which must subclass one of the existing numeric parsers fromFieldCache. Sort type is inferred by testing which numeric parser the parser subclasses.- Throws:
IllegalArgumentException- if the parser fails to subclass an existing numeric parser, or field is null
-
SortField
Creates a sort, possibly in reverse, by terms in the given field, parsed to numeric values using a customFieldCache.Parser.- Parameters:
field- Name of field to sort by. Must not be null.parser- Instance of aFieldCache.Parser, which must subclass one of the existing numeric parsers fromFieldCache. Sort type is inferred by testing which numeric parser the parser subclasses.reverse- True if natural order should be reversed.- Throws:
IllegalArgumentException- if the parser fails to subclass an existing numeric parser, or field is null
-
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
-
setMissingValue
-
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.
-
getParser
Returns the instance of aFieldCacheparser that fits to the given sort type. May returnnullif no parser was specified. Sorting is using the default parser then.- Returns:
- An instance of a
FieldCacheparser, ornull.
-
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 aFieldComparatorSourceorFieldCache.Parserwas provided, it must properly implement equals (unless a singleton is always used). -
hashCode
public int hashCode()Returns true ifois equal to this. If aFieldComparatorSourceorFieldCache.Parserwas 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 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- Throws:
IOException
-
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
-
needsScores
public boolean needsScores()Whether the relevance score is needed to sort documents.
-