Class LuceneIndexKeySerializer
java.lang.Object
com.apple.foundationdb.record.lucene.idformat.LuceneIndexKeySerializer
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 Summary
FieldsModifier and TypeFieldDescriptionstatic final intstatic final intstatic final int -
Constructor Summary
ConstructorsConstructorDescriptionConstruct a new serializer using a format. -
Method Summary
Modifier and TypeMethodDescriptionbyte[][]Serialize the key as aBinaryPoint.byte[][]asPackedBinaryPoint(Tuple key) Serialize the key as aBinaryPointwithout a format.byte[]asPackedByteArray(Tuple key) Serialize the key as a single byte array (this will result in aTuple.pack()).static LuceneIndexKeySerializerfromStringFormat(String formatString) Construct a new serializer using a String format.boolean
-
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
-
LuceneIndexKeySerializer
Construct a new serializer using a format. The format parameter is optional. Absence of the format parameter will cause failure when trying to use theasFormattedBinaryPoint(com.apple.foundationdb.tuple.Tuple)method.- Parameters:
format- optional the key format
-
-
Method Details
-
fromStringFormat
Construct a new serializer using a String format. The format is parsed usingRecordIdFormatParser(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 theasFormattedBinaryPoint(com.apple.foundationdb.tuple.Tuple)method.- Parameters:
formatString- optional string representing the key format- Returns:
- the created serializer
-
asPackedByteArray
Serialize the key as a single byte array (this will result in aTuple.pack()).- Parameters:
key- the key to serialize- Returns:
- the serialized key
-
asPackedBinaryPoint
Serialize the key as aBinaryPointwithout 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
Serialize the key as aBinaryPoint. This method uses the givenRecordIdFormatas 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()
-