Class FieldComparator<T>

    • Constructor Detail

      • FieldComparator

        public FieldComparator()
    • Method Detail

      • compare

        public abstract int compare​(int slot1,
                                    int slot2)
        Compare hit at slot1 with hit at slot2.
        Parameters:
        slot1 - first slot to compare
        slot2 - second slot to compare
        Returns:
        any N < 0 if slot2's value is sorted after slot1, any N > 0 if the slot2's value is sorted before slot1 and 0 if they are equal
      • value

        public abstract T value​(int slot)
        Return the actual value in the slot.
        Parameters:
        slot - the value
        Returns:
        value in this slot
      • getLeafComparator

        public abstract LeafFieldComparator getLeafComparator​(LeafReaderContext context)
                                                       throws java.io.IOException
        Get a per-segment LeafFieldComparator to collect the given LeafReaderContext. All docIDs supplied to this LeafFieldComparator are relative to the current reader (you must add docBase if you need to map it to a top-level docID).
        Parameters:
        context - current reader context
        Returns:
        the comparator to use for this segment
        Throws:
        java.io.IOException - if there is a low-level IO error
      • compareValues

        public int compareValues​(T first,
                                 T second)
        Returns a negative integer if first is less than second, 0 if they are equal and a positive integer otherwise. Default impl to assume the type implements Comparable and invoke .compareTo; be sure to override this method if your FieldComparator's type isn't a Comparable or if your values may sometimes be null
      • setSingleSort

        public void setSingleSort()
        Informs the comparator that sort is done on this single field. This is useful to enable some optimizations for skipping non-competitive documents.
      • disableSkipping

        public void disableSkipping()
        Informs the comparator that the skipping of documents should be disabled. This function is called in cases when the skipping functionality should not be applied or not necessary. One example for numeric comparators is when we don't know if the same numeric data has been indexed with docValues and points if these two fields have the same name. As the skipping functionality relies on these fields to have the same data and as we don't know if it is true, we have to disable it. Another example could be when search sort is a part of the index sort, and can be already efficiently handled by TopFieldCollector, and doing extra work for skipping in the comparator is redundant.