use of com.google.firebase.firestore.local.IndexManager.IndexType in project firebase-android-sdk by firebase.
the class QueryEngine method performQueryUsingIndex.
/**
* Performs an indexed query that evaluates the query based on a collection's persisted index
* values. Returns {@code null} if an index is not available.
*/
@Nullable
private ImmutableSortedMap<DocumentKey, Document> performQueryUsingIndex(Query query) {
if (query.matchesAllDocuments()) {
// Don't use indexes for queries that can be executed by scanning the collection.
return null;
}
Target target = query.toTarget();
IndexType indexType = indexManager.getIndexType(target);
if (indexType.equals(IndexType.NONE)) {
// The target cannot be served from any index.
return null;
}
if (query.hasLimit() && indexType.equals(IndexType.PARTIAL)) {
// in such cases.
return performQueryUsingIndex(query.limitToFirst(Target.NO_LIMIT));
}
List<DocumentKey> keys = indexManager.getDocumentsMatchingTarget(target);
hardAssert(keys != null, "index manager must return results for partial and full indexes.");
ImmutableSortedMap<DocumentKey, Document> indexedDocuments = localDocumentsView.getDocuments(keys);
IndexOffset offset = indexManager.getMinOffset(target);
ImmutableSortedSet<Document> previousResults = applyQuery(query, indexedDocuments);
if (needsRefill(query, keys.size(), previousResults, offset.getReadTime())) {
// incorporated.
return performQueryUsingIndex(query.limitToFirst(Target.NO_LIMIT));
}
return appendRemainingResults(previousResults, query, offset);
}
Aggregations