Class 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 Detail

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