use of com.google.firebase.firestore.model.TargetIndexMatcher in project firebase-android-sdk by firebase.
the class SQLiteIndexManager method getFieldIndex.
@Nullable
@Override
public FieldIndex getFieldIndex(Target target) {
hardAssert(started, "IndexManager not started");
TargetIndexMatcher targetIndexMatcher = new TargetIndexMatcher(target);
String collectionGroup = target.getCollectionGroup() != null ? target.getCollectionGroup() : target.getPath().getLastSegment();
Collection<FieldIndex> collectionIndexes = getFieldIndexes(collectionGroup);
if (collectionIndexes.isEmpty()) {
return null;
}
List<FieldIndex> matchingIndexes = new ArrayList<>();
for (FieldIndex fieldIndex : collectionIndexes) {
boolean matches = targetIndexMatcher.servedByIndex(fieldIndex);
if (matches) {
matchingIndexes.add(fieldIndex);
}
}
if (matchingIndexes.isEmpty()) {
return null;
}
// Return the index with the most number of segments
return Collections.max(matchingIndexes, (l, r) -> Integer.compare(l.getSegments().size(), r.getSegments().size()));
}
Aggregations