Class FieldComparator

java.lang.Object
com.yahoo.search.result.ChainableComparator
com.yahoo.search.result.FieldComparator
All Implemented Interfaces:
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 Details

    • FieldComparator

      public FieldComparator(Sorting sorting)
      Creates a field comparator using a sort order and having no chained comparator
    • FieldComparator

      public FieldComparator(Sorting sorting, Comparator<Hit> secondaryComparator)
      Creates a field comparator using a sort order with a chained comparator
  • Method Details

    • 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.0

      When 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 interface Comparator<Hit>
      Overrides:
      compare in class ChainableComparator
      Returns:
      -1, 0, 1 if first should be sorted before, equal to or after second
    • getField

      public Object getField(Hit hit, String key)
    • toString

      public String toString()
      Overrides:
      toString in class Object