Kishore Nallan
04/02/2025, 9:30 AMdef combine_to_64bit(val1, val2):
"""
Combine two 32-bit integers into a single 64-bit integer using bit shifting.
Args:
val1 (int): First value that will occupy the high 32 bits
val2 (int): Second value that will occupy the low 32 bits
Returns:
int: 64-bit integer combining both values
"""
# Shift first value left by 32 bits
high_bits = val1 << 32
# Combine with second value using bitwise OR
result = high_bits | val2
return result
Using this approach you can actually "pack" stockQuantity
and productViews
into a single field and it will also preserve the sorting order like you would get with 4 sorting fields.
This computed field can be indexed as part of the document and used in sort_by clause.