public class

SortField

extends Object
implements Serializable
java.lang.Object
   ↳ org.apache.lucene.search.SortField

Class Overview

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

See Also

Summary

Constants
int BYTE Sort using term values as encoded Bytes.
int CUSTOM Sort using a custom Comparator.
int DOC Sort by document number (index order).
int DOUBLE Sort using term values as encoded Doubles.
int FLOAT Sort using term values as encoded Floats.
int INT Sort using term values as encoded Integers.
int LONG Sort using term values as encoded Longs.
int SCORE Sort by document score (relevance).
int SHORT Sort using term values as encoded Shorts.
int STRING Sort using term values as Strings.
int STRING_VAL Sort using term values as Strings, but comparing by value (using String.compareTo) for all comparisons.
Fields
public static final SortField FIELD_DOC Represents sorting by document number (index order).
public static final SortField FIELD_SCORE Represents sorting by document score (relevance).
Public Constructors
SortField(String field, int type)
Creates a sort by terms in the given field with the type of term values explicitly given.
SortField(String field, int type, boolean reverse)
Creates a sort, possibly in reverse, by terms in the given field with the type of term values explicitly given.
SortField(String field, FieldCache.Parser parser)
Creates a sort by terms in the given field, parsed to numeric values using a custom FieldCache.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 custom FieldCache.Parser.
SortField(String field, Locale locale)
Creates a sort by terms in the given field sorted according to the given locale.
SortField(String field, Locale locale, boolean reverse)
Creates a sort, possibly in reverse, by terms in the given field sorted according to the given locale.
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.
Public Methods
boolean equals(Object o)
Returns true if o is equal to this.
FieldComparator getComparator(int numHits, int sortPos)
Returns the FieldComparator to use for sorting.@lucene.experimental
FieldComparatorSource getComparatorSource()
Returns the FieldComparatorSource used for custom sorting
String getField()
Returns the name of the field.
Locale getLocale()
Returns the Locale by which term values are interpreted.
FieldCache.Parser getParser()
Returns the instance of a FieldCache parser that fits to the given sort type.
boolean getReverse()
Returns whether the sort should be reversed.
int getType()
Returns the type of contents in the field.
int hashCode()
Returns true if o is equal to this.
String toString()
[Expand]
Inherited Methods
From class java.lang.Object

Constants

public static final int BYTE

Sort using term values as encoded Bytes. Sort values are Byte and lower values are at the front.

Constant Value: 10 (0x0000000a)

public static final int CUSTOM

Sort using a custom Comparator. Sort values are any Comparable and sorting is done according to natural order.

Constant Value: 9 (0x00000009)

public static final int DOC

Sort by document number (index order). Sort values are Integer and lower values are at the front.

Constant Value: 1 (0x00000001)

public static final int DOUBLE

Sort using term values as encoded Doubles. Sort values are Double and lower values are at the front.

Constant Value: 7 (0x00000007)

public static final int FLOAT

Sort using term values as encoded Floats. Sort values are Float and lower values are at the front.

Constant Value: 5 (0x00000005)

public static final int INT

Sort using term values as encoded Integers. Sort values are Integer and lower values are at the front.

Constant Value: 4 (0x00000004)

public static final int LONG

Sort using term values as encoded Longs. Sort values are Long and lower values are at the front.

Constant Value: 6 (0x00000006)

public static final int SCORE

Sort by document score (relevance). Sort values are Float and higher values are at the front.

Constant Value: 0 (0x00000000)

public static final int SHORT

Sort using term values as encoded Shorts. Sort values are Short and lower values are at the front.

Constant Value: 8 (0x00000008)

public static final int STRING

Sort using term values as Strings. Sort values are String and lower values are at the front.

Constant Value: 3 (0x00000003)

public static final int STRING_VAL

Sort using term values as Strings, but comparing by value (using String.compareTo) for all comparisons. This is typically slower than STRING, which uses ordinals to do the sorting.

Constant Value: 11 (0x0000000b)

Fields

public static final SortField FIELD_DOC

Represents sorting by document number (index order).

public static final SortField FIELD_SCORE

Represents sorting by document score (relevance).

Public Constructors

public SortField (String field, int type)

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 be null if type is SCORE or DOC.
type Type of values in the terms.

public SortField (String field, int type, boolean reverse)

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 be null if type is SCORE or DOC.
type Type of values in the terms.
reverse True if natural order should be reversed.

public SortField (String field, FieldCache.Parser parser)

Creates a sort by terms in the given field, parsed to numeric values using a custom FieldCache.Parser.

Parameters
field Name of field to sort by. Must not be null.
parser Instance of a FieldCache.Parser, which must subclass one of the existing numeric parsers from FieldCache. 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

public 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 custom FieldCache.Parser.

Parameters
field Name of field to sort by. Must not be null.
parser Instance of a FieldCache.Parser, which must subclass one of the existing numeric parsers from FieldCache. 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

public SortField (String field, Locale locale)

Creates a sort by terms in the given field sorted according to the given locale.

Parameters
field Name of field to sort by, cannot be null.
locale Locale of values in the field.

public SortField (String field, Locale locale, boolean reverse)

Creates a sort, possibly in reverse, by terms in the given field sorted according to the given locale.

Parameters
field Name of field to sort by, cannot be null.
locale Locale of values in the field.

public SortField (String field, FieldComparatorSource comparator)

Creates a sort with a custom comparison function.

Parameters
field Name of field to sort by; cannot be null.
comparator Returns a comparator for sorting hits.

public SortField (String field, FieldComparatorSource comparator, boolean reverse)

Creates a sort, possibly in reverse, with a custom comparison function.

Parameters
field Name of field to sort by; cannot be null.
comparator Returns a comparator for sorting hits.
reverse True if natural order should be reversed.

Public Methods

public boolean equals (Object o)

Returns true if o is equal to this. If a FieldComparatorSource or FieldCache.Parser was provided, it must properly implement equals (unless a singleton is always used).

public FieldComparator getComparator (int numHits, int sortPos)

Returns the FieldComparator to use for sorting.@lucene.experimental

Parameters
numHits number of top hits the queue will store
sortPos position of this SortField within Sort. The comparator is primary if sortPos==0, secondary if sortPos==1, etc. Some comparators can optimize themselves when they are the primary sort.
Returns
Throws
IOException

public FieldComparatorSource getComparatorSource ()

Returns the FieldComparatorSource used for custom sorting

public String getField ()

Returns the name of the field. Could return null if the sort is by SCORE or DOC.

Returns
  • Name of field, possibly null.

public Locale getLocale ()

Returns the Locale by which term values are interpreted. May return null if no Locale was specified.

Returns
  • Locale, or null.

public FieldCache.Parser getParser ()

Returns the instance of a FieldCache parser that fits to the given sort type. May return null if no parser was specified. Sorting is using the default parser then.

Returns

public boolean getReverse ()

Returns whether the sort should be reversed.

Returns
  • True if natural order should be reversed.

public int getType ()

Returns the type of contents in the field.

Returns
  • One of the constants SCORE, DOC, STRING, INT or FLOAT.

public int hashCode ()

Returns true if o is equal to this. If a FieldComparatorSource or FieldCache.Parser was provided, it must properly implement hashCode (unless a singleton is always used).

public String toString ()