public class SortField extends Object
Created: Feb 11, 2004 1:25:29 PM
Sort
Modifier and Type | Class and Description |
---|---|
static class |
SortField.Type
Specifies the type of the terms to be sorted, or special types such as CUSTOM
|
Modifier and Type | Field and Description |
---|---|
static SortField |
FIELD_DOC
Represents sorting by document number (index order).
|
static SortField |
FIELD_SCORE
Represents sorting by document score (relevance).
|
Object |
missingValue |
static Object |
STRING_FIRST
Pass this to
setMissingValue(java.lang.Object) to have missing
string values sort first. |
static Object |
STRING_LAST
Pass this to
setMissingValue(java.lang.Object) to have missing
string values sort last. |
Constructor and Description |
---|
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,
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.
|
Modifier and Type | Method and Description |
---|---|
boolean |
equals(Object o)
Returns true if
o is equal to this. |
Comparator<BytesRef> |
getBytesComparator() |
FieldComparator<?> |
getComparator(int numHits,
int sortPos)
Returns the
FieldComparator to use for
sorting. |
FieldComparatorSource |
getComparatorSource()
Returns the
FieldComparatorSource used for
custom sorting |
String |
getField()
Returns the name of the field.
|
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.
|
SortField.Type |
getType()
Returns the type of contents in the field.
|
int |
hashCode()
Returns true if
o is equal to this. |
boolean |
needsScores()
Whether the relevance score is needed to sort documents.
|
SortField |
rewrite(IndexSearcher searcher)
Rewrites this SortField, returning a new SortField if a change is made.
|
void |
setBytesComparator(Comparator<BytesRef> b) |
void |
setMissingValue(Object missingValue) |
String |
toString() |
public static final SortField FIELD_SCORE
public static final SortField FIELD_DOC
public Object missingValue
public static final Object STRING_FIRST
setMissingValue(java.lang.Object)
to have missing
string values sort first.public static final Object STRING_LAST
setMissingValue(java.lang.Object)
to have missing
string values sort last.public SortField(String field, SortField.Type 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, SortField.Type 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 nullpublic 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 nullpublic 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, 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.public void setMissingValue(Object missingValue)
public String getField()
null
if the sort is by SCORE or DOC.null
.public SortField.Type getType()
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 FieldComparatorSource getComparatorSource()
FieldComparatorSource
used for
custom sortingpublic boolean equals(Object o)
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 int hashCode()
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 void setBytesComparator(Comparator<BytesRef> b)
public Comparator<BytesRef> getBytesComparator()
public FieldComparator<?> getComparator(int numHits, int sortPos) throws IOException
FieldComparator
to use for
sorting.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 sortingIOException
public SortField rewrite(IndexSearcher searcher) throws IOException
SortField.Type.REWRITEABLE
searcher
- IndexSearcher to use during rewritingthis
if nothing has changed.IOException
- Can be thrown by the rewritingpublic boolean needsScores()
Copyright © 2000-2014 Apache Software Foundation. All Rights Reserved.