Search in sources :

Example 1 with IndexEntry

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;
}
Also used : FieldIndex(com.google.firebase.firestore.model.FieldIndex) TreeSet(java.util.TreeSet) Value(com.google.firestore.v1.Value) IndexEntry(com.google.firebase.firestore.index.IndexEntry) Nullable(androidx.annotation.Nullable)

Example 2 with IndexEntry

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);
            }
        }
    }
}
Also used : FieldIndex(com.google.firebase.firestore.model.FieldIndex) DocumentKey(com.google.firebase.firestore.model.DocumentKey) IndexEntry(com.google.firebase.firestore.index.IndexEntry) Document(com.google.firebase.firestore.model.Document) HashMap(java.util.HashMap) Map(java.util.Map) ImmutableSortedMap(com.google.firebase.database.collection.ImmutableSortedMap)

Aggregations

IndexEntry (com.google.firebase.firestore.index.IndexEntry)2 FieldIndex (com.google.firebase.firestore.model.FieldIndex)2 Nullable (androidx.annotation.Nullable)1 ImmutableSortedMap (com.google.firebase.database.collection.ImmutableSortedMap)1 Document (com.google.firebase.firestore.model.Document)1 DocumentKey (com.google.firebase.firestore.model.DocumentKey)1 Value (com.google.firestore.v1.Value)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 TreeSet (java.util.TreeSet)1