Package com.yahoo.search.result
Class FieldComparator
- java.lang.Object
-
- com.yahoo.search.result.ChainableComparator
-
- com.yahoo.search.result.FieldComparator
-
- All Implemented Interfaces:
java.util.Comparator<Hit>
public class FieldComparator extends ChainableComparator
Comparator used for ordering hits using the field values and a sorting specification.Note: this comparator imposes orderings that are inconsistent with equals.
- Author:
- Steinar Knutsen
-
-
Constructor Summary
Constructors Constructor Description FieldComparator(Sorting sorting)
Creates a field comparator using a sort order and having no chained comparatorFieldComparator(Sorting sorting, java.util.Comparator<Hit> secondaryComparator)
Creates a field comparator using a sort order with a chained comparator
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description int
compare(Hit first, Hit second)
Compares hits based on a sorting specification and values stored in hit fields.0static FieldComparator
create(Sorting sorting)
Creates a comparator given a sorting, or returns null if the given sorting is nulljava.lang.Object
getField(Hit hit, java.lang.String key)
java.lang.String
toString()
-
Methods inherited from class com.yahoo.search.result.ChainableComparator
getSecondaryComparator
-
-
-
-
Constructor Detail
-
FieldComparator
public FieldComparator(Sorting sorting)
Creates a field comparator using a sort order and having no chained comparator
-
-
Method Detail
-
create
public static FieldComparator create(Sorting sorting)
Creates a comparator given a sorting, or returns null if the given sorting is null
-
compare
public int compare(Hit first, Hit second)
Compares hits based on a sorting specification and values stored in hit fields.0When one of the hits has the requested property and the other has not, the the hit containing the property precedes the one that does not.
There is no locale based sorting here, as the backend does not do that either.
- Specified by:
compare
in interfacejava.util.Comparator<Hit>
- Overrides:
compare
in classChainableComparator
- Returns:
- -1, 0, 1 if first should be sorted before, equal to or after second
-
getField
public java.lang.Object getField(Hit hit, java.lang.String key)
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
-