Class LuceneIndexKeySerializer

java.lang.Object
com.apple.foundationdb.record.lucene.idformat.LuceneIndexKeySerializer

public class LuceneIndexKeySerializer extends Object
A class that serializes the Index primary keys according to a format. When the LuceneIndexMaintainer writes an index entry, there are several ways by which the index primary key can be written (stored, sortable, binarypoint, etc). This class generates the key values that can be written to the document. The key being serialized is the Tuple that represents the ID for the entry. The serialized format is a byte array (e.g. it can be simply a Tuple.pack() in some cases, and can take other forms like BinaryPoint for fast lookup). This class uses a RecordIdFormat as a guide to the way that the serialized form is to be generated. The Format contains instructions regarding the types and nesting hierarchy of the key so that the generated format is unique, consistent and searchable. Of note are the constraints of BinaryPoint: All dimensions should be of the same length, we cannot change the dimension length or the number of dimensions once an entry has been written (all entries should have the same dimensions). As a consequence, this class allocates (and pads the byte arrays) the maximum size for each component of the binary point. This leads to some waste, but is necessary in order to support the format.
  • Field Details

    • BINARY_POINT_DIMENSION_SIZE

      public static final int BINARY_POINT_DIMENSION_SIZE
      See Also:
    • MAX_STRING_16_LENGTH

      public static final int MAX_STRING_16_LENGTH
      See Also:
    • MAX_STRING_16_ENCODED_LENGTH

      public static final int MAX_STRING_16_ENCODED_LENGTH
      See Also:
  • Constructor Details

  • Method Details

    • fromStringFormat

      public static LuceneIndexKeySerializer fromStringFormat(@Nullable String formatString)
      Construct a new serializer using a String format. The format is parsed using RecordIdFormatParser (see that class for a description of the syntax). The format parameter is optional. Absence of the format parameter will cause failure when trying to use the asFormattedBinaryPoint(com.apple.foundationdb.tuple.Tuple) method.
      Parameters:
      formatString - optional string representing the key format
      Returns:
      the created serializer
    • asPackedByteArray

      public byte[] asPackedByteArray(@Nonnull Tuple key)
      Serialize the key as a single byte array (this will result in a Tuple.pack()).
      Parameters:
      key - the key to serialize
      Returns:
      the serialized key
    • asPackedBinaryPoint

      public byte[][] asPackedBinaryPoint(@Nonnull Tuple key)
      Serialize the key as a BinaryPoint without a format. This format SHOULD NOT be used to store in Lucene as it is not guaranteed to be of fixed length. As the content grows, it may generate more dimensions.
      Parameters:
      key - the key to serialize
      Returns:
      the split (BinaryPoint) style serialized key
    • asFormattedBinaryPoint

      public byte[][] asFormattedBinaryPoint(@Nonnull Tuple key) throws RecordCoreFormatException
      Serialize the key as a BinaryPoint. This method uses the given RecordIdFormat as a guide to ensure the returned BinaryPoint is going to be of fixed length, and searchable (by separating the components to different dimensions, thus allowing range searches).
      Parameters:
      key - the key to serialize
      Returns:
      the formatted serialized key
      Throws:
      RecordCoreFormatException - in case there is no format or the format failed to parse or validate
    • hasFormat

      public boolean hasFormat()