Skip to content

Commit a31fa87

Browse files
committed
OR Queries.
Add Filter.Java. Remove core/Filter.Java. Add CompositeFilter.java. Make the Filter class abstract. Purely formatting change. (ran googleJavaFormat). Added UnqualifiedFieldFilter, and `where` API. Update core/Query.java to be "aware" of composite filters. Fix the logic for `matches(doc)` for CompositeFilters. Fix remaining usages. Update RemoteSerializer.java. Add TODO for bundles. Add the other filter APIs. integrate with indexing. Respect the limit when evaluating multiple dnf terms. Remove UnqualifiedFieldFilter. Move validation to the right place. Don't impose limit on sub-filter queries. Enforce limit constraint for queries with more than 1 DNF term. Add the parsed filter to the query.
1 parent 4231f58 commit a31fa87

File tree

22 files changed

+1119
-569
lines changed

22 files changed

+1119
-569
lines changed

firebase-firestore/src/main/java/com/google/firebase/firestore/DocumentReference.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ static DocumentReference forPath(ResourcePath path, FirebaseFirestore firestore)
8484
return new DocumentReference(DocumentKey.fromPath(path), firestore);
8585
}
8686

87-
DocumentKey getKey() {
87+
public DocumentKey getKey() {
8888
return key;
8989
}
9090

Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
package com.google.firebase.firestore;
2+
3+
import androidx.annotation.NonNull;
4+
import androidx.annotation.Nullable;
5+
import com.google.firebase.firestore.core.CompositeFilter;
6+
import com.google.firebase.firestore.core.FieldFilter;
7+
import com.google.firebase.firestore.core.Query;
8+
import com.google.firebase.firestore.model.Document;
9+
import java.util.Arrays;
10+
11+
public abstract class Filter {
12+
@NonNull
13+
public static Filter equalTo(@NonNull String field, @Nullable Object value) {
14+
return equalTo(FieldPath.fromDotSeparatedPath(field), value);
15+
}
16+
17+
@NonNull
18+
public static Filter equalTo(@NonNull FieldPath fieldPath, @Nullable Object value) {
19+
return FieldFilter.create(fieldPath.getInternalPath(), FieldFilter.Operator.EQUAL, value);
20+
}
21+
22+
@NonNull
23+
public static Filter notEqualTo(@NonNull String field, @Nullable Object value) {
24+
return notEqualTo(FieldPath.fromDotSeparatedPath(field), value);
25+
}
26+
27+
@NonNull
28+
public static Filter notEqualTo(@NonNull FieldPath fieldPath, @Nullable Object value) {
29+
return FieldFilter.create(fieldPath.getInternalPath(), FieldFilter.Operator.NOT_EQUAL, value);
30+
}
31+
32+
@NonNull
33+
public static Filter greaterThan(@NonNull String field, @Nullable Object value) {
34+
return greaterThan(FieldPath.fromDotSeparatedPath(field), value);
35+
}
36+
37+
@NonNull
38+
public static Filter greaterThan(@NonNull FieldPath fieldPath, @Nullable Object value) {
39+
return FieldFilter.create(
40+
fieldPath.getInternalPath(), FieldFilter.Operator.GREATER_THAN, value);
41+
}
42+
43+
@NonNull
44+
public static Filter greaterThanOrEqualTo(@NonNull String field, @Nullable Object value) {
45+
return greaterThanOrEqualTo(FieldPath.fromDotSeparatedPath(field), value);
46+
}
47+
48+
@NonNull
49+
public static Filter greaterThanOrEqualTo(@NonNull FieldPath fieldPath, @Nullable Object value) {
50+
return FieldFilter.create(
51+
fieldPath.getInternalPath(), FieldFilter.Operator.GREATER_THAN_OR_EQUAL, value);
52+
}
53+
54+
@NonNull
55+
public static Filter lessThan(@NonNull String field, @Nullable Object value) {
56+
return lessThan(FieldPath.fromDotSeparatedPath(field), value);
57+
}
58+
59+
@NonNull
60+
public static Filter lessThan(@NonNull FieldPath fieldPath, @Nullable Object value) {
61+
return FieldFilter.create(fieldPath.getInternalPath(), FieldFilter.Operator.LESS_THAN, value);
62+
}
63+
64+
@NonNull
65+
public static Filter lessThanOrEqualTo(@NonNull String field, @Nullable Object value) {
66+
return lessThanOrEqualTo(FieldPath.fromDotSeparatedPath(field), value);
67+
}
68+
69+
@NonNull
70+
public static Filter lessThanOrEqualTo(@NonNull FieldPath fieldPath, @Nullable Object value) {
71+
return FieldFilter.create(
72+
fieldPath.getInternalPath(), FieldFilter.Operator.LESS_THAN_OR_EQUAL, value);
73+
}
74+
75+
@NonNull
76+
public static Filter arrayContains(@NonNull String field, @Nullable Object value) {
77+
return arrayContains(FieldPath.fromDotSeparatedPath(field), value);
78+
}
79+
80+
@NonNull
81+
public static Filter arrayContains(@NonNull FieldPath fieldPath, @Nullable Object value) {
82+
return FieldFilter.create(
83+
fieldPath.getInternalPath(), FieldFilter.Operator.ARRAY_CONTAINS, value);
84+
}
85+
86+
@NonNull
87+
public static Filter arrayContainsAny(@NonNull String field, @Nullable Object value) {
88+
return arrayContainsAny(FieldPath.fromDotSeparatedPath(field), value);
89+
}
90+
91+
@NonNull
92+
public static Filter arrayContainsAny(@NonNull FieldPath fieldPath, @Nullable Object value) {
93+
return FieldFilter.create(
94+
fieldPath.getInternalPath(), FieldFilter.Operator.ARRAY_CONTAINS_ANY, value);
95+
}
96+
97+
@NonNull
98+
public static Filter in(@NonNull String field, @Nullable Object value) {
99+
return in(FieldPath.fromDotSeparatedPath(field), value);
100+
}
101+
102+
@NonNull
103+
public static Filter in(@NonNull FieldPath fieldPath, @Nullable Object value) {
104+
return FieldFilter.create(fieldPath.getInternalPath(), FieldFilter.Operator.IN, value);
105+
}
106+
107+
@NonNull
108+
public static Filter notIn(@NonNull String field, @Nullable Object value) {
109+
return notIn(FieldPath.fromDotSeparatedPath(field), value);
110+
}
111+
112+
@NonNull
113+
public static Filter notIn(@NonNull FieldPath fieldPath, @Nullable Object value) {
114+
return FieldFilter.create(fieldPath.getInternalPath(), FieldFilter.Operator.NOT_IN, value);
115+
}
116+
117+
@NonNull
118+
public static Filter or(Filter... filters) {
119+
return new CompositeFilter(Arrays.asList(filters), /*isAnd*/ false);
120+
}
121+
122+
@NonNull
123+
public static Filter and(Filter... filters) {
124+
return new CompositeFilter(Arrays.asList(filters), /*isAnd*/ true);
125+
}
126+
127+
public abstract Query apply(Query query, FirebaseFirestore firestore);
128+
129+
public abstract boolean matches(Document doc);
130+
131+
public abstract String getCanonicalId();
132+
}

firebase-firestore/src/main/java/com/google/firebase/firestore/FirebaseFirestore.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -761,11 +761,11 @@ FirestoreClient getClient() {
761761
return client;
762762
}
763763

764-
DatabaseId getDatabaseId() {
764+
public DatabaseId getDatabaseId() {
765765
return databaseId;
766766
}
767767

768-
UserDataReader getUserDataReader() {
768+
public UserDataReader getUserDataReader() {
769769
return userDataReader;
770770
}
771771

0 commit comments

Comments
 (0)