use of com.google.firebase.firestore.index.IndexEntry in project firebase-android-sdk by firebase.
the class SQLiteIndexManager method computeIndexEntries.
/**
* Creates the index entries for the given document.
*/
private SortedSet<IndexEntry> computeIndexEntries(Document document, FieldIndex fieldIndex) {
SortedSet<IndexEntry> result = new TreeSet<>();
@Nullable byte[] directionalValue = encodeDirectionalElements(fieldIndex, document);
if (directionalValue == null) {
return result;
}
@Nullable FieldIndex.Segment arraySegment = fieldIndex.getArraySegment();
if (arraySegment != null) {
Value value = document.getField(arraySegment.getFieldPath());
if (isArray(value)) {
for (Value arrayValue : value.getArrayValue().getValuesList()) {
result.add(IndexEntry.create(fieldIndex.getIndexId(), document.getKey(), encodeSingleElement(arrayValue), directionalValue));
}
}
} else {
result.add(IndexEntry.create(fieldIndex.getIndexId(), document.getKey(), new byte[] {}, directionalValue));
}
return result;
}
use of com.google.firebase.firestore.index.IndexEntry in project firebase-android-sdk by firebase.
the class SQLiteIndexManager method updateIndexEntries.
@Override
public void updateIndexEntries(ImmutableSortedMap<DocumentKey, Document> documents) {
hardAssert(started, "IndexManager not started");
for (Map.Entry<DocumentKey, Document> entry : documents) {
Collection<FieldIndex> fieldIndexes = getFieldIndexes(entry.getKey().getCollectionGroup());
for (FieldIndex fieldIndex : fieldIndexes) {
SortedSet<IndexEntry> existingEntries = getExistingIndexEntries(entry.getKey(), fieldIndex);
SortedSet<IndexEntry> newEntries = computeIndexEntries(entry.getValue(), fieldIndex);
if (!existingEntries.equals(newEntries)) {
updateEntries(entry.getValue(), existingEntries, newEntries);
}
}
}
}
Aggregations