Class SortedSetSortField

java.lang.Object
org.apache.lucene.search.SortField
org.apache.lucene.search.SortedSetSortField

public class SortedSetSortField extends SortField
SortField for SortedSetDocValues.

A SortedSetDocValues contains multiple values for a field, so sorting with this technique "selects" a value as the representative sort value for the document.

By default, the minimum value in the set is selected as the sort value, but this can be customized. Selectors other than the default do have some limitations to ensure that all selections happen in constant-time for performance.

Like sorting by string, this also supports sorting missing values as first or last, via setMissingValue(Object).

See Also:
  • Field Details

  • Constructor Details

    • SortedSetSortField

      public SortedSetSortField(String field, boolean reverse)
      Creates a sort, possibly in reverse, by the minimum value in the set for the document.
      Parameters:
      field - Name of field to sort by. Must not be null.
      reverse - True if natural order should be reversed.
    • SortedSetSortField

      public SortedSetSortField(String field, boolean reverse, SortedSetSelector.Type selector)
      Creates a sort, possibly in reverse, specifying how the sort value from the document's set is selected.
      Parameters:
      field - Name of field to sort by. Must not be null.
      reverse - True if natural order should be reversed.
      selector - custom selector type for choosing the sort value from the set.

      NOTE: selectors other than SortedSetSelector.Type.MIN require optional codec support.

  • Method Details

    • readSelectorType

      private static SortedSetSelector.Type readSelectorType(DataInput in) throws IOException
      Throws:
      IOException
    • serialize

      private void serialize(DataOutput out) throws IOException
      Throws:
      IOException
    • getSelector

      public SortedSetSelector.Type getSelector()
      Returns the selector in use for this sort
    • hashCode

      public int hashCode()
      Description copied from class: SortField
      Returns a hash code for this SortField instance. If a FieldComparatorSource was provided, it must properly implement hashCode (unless a singleton is always used).
      Overrides:
      hashCode in class SortField
    • equals

      public boolean equals(Object obj)
      Description copied from class: SortField
      Returns true if o is equal to this. If a FieldComparatorSource was provided, it must properly implement equals (unless a singleton is always used). canUsePoints field is not part of equals and hasCode intentionally, as it is only useful during search-time and using it in these functions prevents index sorting optimizations that rely on the equality of the index-time and search-time SortField instances.
      Overrides:
      equals in class SortField
    • toString

      public String toString()
      Overrides:
      toString in class SortField
    • setMissingValue

      public void setMissingValue(Object missingValue)
      Set how missing values (the empty set) are sorted.

      Note that this must be SortField.STRING_FIRST or SortField.STRING_LAST.

      Overrides:
      setMissingValue in class SortField
    • getComparator

      public FieldComparator<?> getComparator(int numHits, int sortPos)
      Description copied from class: SortField
      Returns the FieldComparator to use for sorting.
      Overrides:
      getComparator in class SortField
      Parameters:
      numHits - number of top hits the queue will store
      sortPos - 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.
      Returns:
      FieldComparator to use when sorting
    • getValues

      private SortedDocValues getValues(LeafReader reader) throws IOException
      Throws:
      IOException
    • getIndexSorter

      public IndexSorter getIndexSorter()
      Description copied from class: SortField
      Returns an IndexSorter used for sorting index segments by this SortField. If the SortField cannot be used for index sorting (for example, if it uses scores or other query-dependent values) then this method should return null SortFields that implement this method should also implement a companion SortFieldProvider to serialize and deserialize the sort in index segment headers
      Overrides:
      getIndexSorter in class SortField