public class SortField
extends java.lang.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 |
---|---|
private java.util.Comparator<BytesRef> |
bytesComparator |
private FieldComparatorSource |
comparatorSource |
private java.lang.String |
field |
static SortField |
FIELD_DOC
Represents sorting by document number (index order).
|
static SortField |
FIELD_SCORE
Represents sorting by document score (relevance).
|
protected java.lang.Object |
missingValue |
(package private) boolean |
reverse |
static java.lang.Object |
STRING_FIRST
Pass this to
setMissingValue(java.lang.Object) to have missing
string values sort first. |
static java.lang.Object |
STRING_LAST
Pass this to
setMissingValue(java.lang.Object) to have missing
string values sort last. |
private SortField.Type |
type |
Constructor and Description |
---|
SortField(java.lang.String field,
FieldComparatorSource comparator)
Creates a sort with a custom comparison function.
|
SortField(java.lang.String field,
FieldComparatorSource comparator,
boolean reverse)
Creates a sort, possibly in reverse, with a custom comparison function.
|
SortField(java.lang.String field,
SortField.Type type)
Creates a sort by terms in the given field with the type of term
values explicitly given.
|
SortField(java.lang.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(java.lang.Object o)
Returns true if
o is equal to this. |
java.util.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 |
java.lang.String |
getField()
Returns the name of the field.
|
java.lang.Object |
getMissingValue()
Return the value to use for documents that don't have a value.
|
boolean |
getReverse()
Returns whether the sort should be reversed.
|
SortField.Type |
getType()
Returns the type of contents in the field.
|
int |
hashCode()
Returns a hash code for this
SortField instance. |
private void |
initFieldType(java.lang.String field,
SortField.Type type) |
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(java.util.Comparator<BytesRef> b) |
void |
setMissingValue(java.lang.Object missingValue)
Set the value to use for documents that don't have a value.
|
java.lang.String |
toString() |
public static final SortField FIELD_SCORE
public static final SortField FIELD_DOC
private java.lang.String field
private SortField.Type type
boolean reverse
private FieldComparatorSource comparatorSource
protected java.lang.Object missingValue
public static final java.lang.Object STRING_FIRST
setMissingValue(java.lang.Object)
to have missing
string values sort first.public static final java.lang.Object STRING_LAST
setMissingValue(java.lang.Object)
to have missing
string values sort last.private java.util.Comparator<BytesRef> bytesComparator
public SortField(java.lang.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(java.lang.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(java.lang.String field, FieldComparatorSource comparator)
field
- Name of field to sort by; cannot be null
.comparator
- Returns a comparator for sorting hits.public SortField(java.lang.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 java.lang.Object getMissingValue()
null
indicates that default should be used.public void setMissingValue(java.lang.Object missingValue)
private void initFieldType(java.lang.String field, SortField.Type type)
public java.lang.String getField()
null
if the sort is by SCORE or DOC.null
.public SortField.Type getType()
public boolean getReverse()
public FieldComparatorSource getComparatorSource()
FieldComparatorSource
used for
custom sortingpublic java.lang.String toString()
toString
in class java.lang.Object
public boolean equals(java.lang.Object o)
o
is equal to this. If a
FieldComparatorSource
was provided, it must properly
implement equals (unless a singleton is always used).equals
in class java.lang.Object
public int hashCode()
SortField
instance. If a
FieldComparatorSource
was provided, it must properly
implement hashCode (unless a singleton is always used).hashCode
in class java.lang.Object
public void setBytesComparator(java.util.Comparator<BytesRef> b)
public java.util.Comparator<BytesRef> getBytesComparator()
public FieldComparator<?> getComparator(int numHits, int sortPos)
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 sortingpublic SortField rewrite(IndexSearcher searcher) throws java.io.IOException
SortField.Type.REWRITEABLE
searcher
- IndexSearcher to use during rewritingthis
if nothing has changed.java.io.IOException
- Can be thrown by the rewritingpublic boolean needsScores()