| 
 | ||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.apache.lucene.search.SortField
public class 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
Sort, 
Serialized Form| Field Summary | |
|---|---|
| static int | AUTODeprecated. Please specify the exact type, instead. Especially, guessing does not work with the new NumericFieldtype. | 
| static int | BYTESort using term values as encoded Bytes. | 
| static int | CUSTOMSort using a custom Comparator. | 
| static int | DOCSort by document number (index order). | 
| static int | DOUBLESort using term values as encoded Doubles. | 
| static SortField | FIELD_DOCRepresents sorting by document number (index order). | 
| static SortField | FIELD_SCORERepresents sorting by document score (relevancy). | 
| static int | FLOATSort using term values as encoded Floats. | 
| static int | INTSort using term values as encoded Integers. | 
| static int | LONGSort using term values as encoded Longs. | 
| static int | SCORESort by document score (relevancy). | 
| static int | SHORTSort using term values as encoded Shorts. | 
| static int | STRINGSort using term values as Strings. | 
| static int | STRING_VALSort using term values as Strings, but comparing by value (using String.compareTo) for all comparisons. | 
| Constructor Summary | |
|---|---|
| SortField(String field)Deprecated. Please specify the exact type instead. | |
| SortField(String field,
          boolean reverse)Deprecated. Please specify the exact type instead. | |
| 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,
          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,
          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,
          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,
          SortComparatorSource comparator)Deprecated. use SortField (String field, FieldComparatorSource comparator) | |
| SortField(String field,
          SortComparatorSource comparator,
          boolean reverse)Deprecated. use SortField (String field, FieldComparatorSource comparator, boolean reverse) | |
| Method Summary | |
|---|---|
|  boolean | equals(Object o)Returns true if ois equal to this. | 
|  FieldComparator | getComparator(int numHits,
              int sortPos)Returns the FieldComparatorto use for
 sorting. | 
|  FieldComparatorSource | getComparatorSource() | 
|  SortComparatorSource | getFactory()Deprecated. use getComparatorSource() | 
|  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 FieldCacheparser 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. | 
|  boolean | getUseLegacySearch()Deprecated. will be removed in Lucene 3.0. | 
|  int | hashCode()Returns true if ois equal to this. | 
|  void | setUseLegacySearch(boolean legacy)Deprecated. will be removed in Lucene 3.0. | 
|  String | toString() | 
| Methods inherited from class java.lang.Object | 
|---|
| clone, finalize, getClass, notify, notifyAll, wait, wait, wait | 
| Field Detail | 
|---|
public static final int SCORE
public static final int DOC
public static final int AUTO
NumericField type.
public static final int STRING
public static final int INT
public static final int FLOAT
public static final int LONG
public static final int DOUBLE
public static final int SHORT
public static final int CUSTOM
public static final int BYTE
public static final int STRING_VAL
STRING, which
 uses ordinals to do the sorting.
public static final SortField FIELD_SCORE
public static final SortField FIELD_DOC
| Constructor Detail | 
|---|
public SortField(String field)
AUTO).
field - Name of field to sort by, cannot be
 null.
public SortField(String field,
                 boolean reverse)
AUTO).
field - Name of field to sort by, cannot be null.reverse - True if natural order should be reversed.
public SortField(String field,
                 int type)
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)
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)
FieldCache.Parser.
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.
IllegalArgumentException - if the parser fails to
  subclass an existing numeric parser, or field is null
public SortField(String field,
                 FieldCache.Parser parser,
                 boolean reverse)
FieldCache.Parser.
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.
IllegalArgumentException - if the parser fails to
  subclass an existing numeric parser, or field is null
public SortField(String field,
                 Locale locale)
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)
field - Name of field to sort by, cannot be null.locale - Locale of values in the field.
public SortField(String field,
                 SortComparatorSource comparator)
field - Name of field to sort by; cannot be null.comparator - Returns a comparator for sorting hits.
public SortField(String field,
                 FieldComparatorSource comparator)
field - Name of field to sort by; cannot be null.comparator - Returns a comparator for sorting hits.
public SortField(String field,
                 SortComparatorSource comparator,
                 boolean reverse)
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 SortField(String field,
                 FieldComparatorSource comparator,
                 boolean reverse)
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.| Method Detail | 
|---|
public String getField()
null
 if the sort is by SCORE or DOC.
null.public int getType()
public Locale getLocale()
null if no Locale was specified.
null.public FieldCache.Parser getParser()
FieldCache parser that fits to the given sort type.
 May return null if no parser was specified. Sorting is using the default parser then.
FieldCache parser, or null.public boolean getReverse()
public SortComparatorSource getFactory()
getComparatorSource()
public FieldComparatorSource getComparatorSource()
public void setUseLegacySearch(boolean legacy)
legacy - true for legacy behaviorpublic boolean getUseLegacySearch()
public String toString()
toString in class Objectpublic boolean equals(Object o)
o is equal to this.  If a
  SortComparatorSource (deprecated) or FieldCache.Parser was provided, it must properly
  implement equals (unless a singleton is always used).
equals in class Objectpublic int hashCode()
o is equal to this.  If a
  SortComparatorSource (deprecated) or FieldCache.Parser was provided, it must properly
  implement hashCode (unless a singleton is always
  used).
hashCode in class Object
public FieldComparator getComparator(int numHits,
                                     int sortPos)
                              throws IOException
FieldComparator to use for
 sorting.
 NOTE: This API is experimental and might change in
 incompatible ways in the next release.
numHits - number of top hits the queue will storesortPos - 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.
FieldComparator to use when sorting
IOException| 
 | ||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||