Class BinarySortField

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

public class BinarySortField extends SortField
SortField for BinaryDocValues, usable as an index sort.

Unlike a SortField.Type.STRING sort (backed by SortedDocValues), values are compared directly rather than through a term dictionary, making this a good fit for high-cardinality fields where a dictionary would be pure overhead. Documents are ordered by the unsigned byte order of their sort key (BytesRef.compareTo(org.apache.lucene.util.BytesRef)), optionally reversed, with missing values sorted first or last via SortField.STRING_FIRST / SortField.STRING_LAST (first by default).

By default the sort key is the stored value. A subclass may override getSortKeyDocValues(LeafReader) to derive an order-preserving key from the stored bytes and/or other doc-values fields of the segment (for example to select the minimum of a multi-valued field). Such a subclass must register a SortFieldProvider via SPI so the sort can be read back and used on merge.

This field can also sort search results, comparing values with a linear scan of the binary doc values (without the skipping optimizations available to numeric or SORTED fields).

WARNING: This API is experimental and might change in incompatible ways in the next release.
  • Constructor Details

    • BinarySortField

      public BinarySortField(String field, boolean reverse)
      Creates a sort, possibly in reverse, by the unsigned byte order of the field's value.
      Parameters:
      field - Name of field to sort by. Must not be null.
      reverse - True if natural order should be reversed.
    • BinarySortField

      public BinarySortField(String field, boolean reverse, Object missingValue)
      Creates a sort, possibly in reverse, by the unsigned byte order of the field's value, with the given handling of missing values.
      Parameters:
      field - Name of field to sort by. Must not be null.
      reverse - True if natural order should be reversed.
      missingValue - SortField.STRING_FIRST, SortField.STRING_LAST, or null (missing first).
    • BinarySortField

      protected BinarySortField(String field, boolean reverse, Object missingValue, String providerName)
      Creates a sort for a subclass that overrides getSortKeyDocValues(LeafReader).

      The subclass must supply the name of a dedicated SortFieldProvider (registered via SPI) whose SortFieldProvider.readSortField(org.apache.lucene.store.DataInput) reconstructs the subclass, so that the same sort-key derivation is used when the index sort is read back and on merge.

      Parameters:
      field - Name of field to sort by. Must not be null.
      reverse - True if natural order should be reversed.
      missingValue - SortField.STRING_FIRST, SortField.STRING_LAST, or null.
      providerName - the SPI name of the companion SortFieldProvider.
  • Method Details