Skip to content

Commit 39262c8

Browse files
Small indexing fixes (#3275)
1 parent 514402d commit 39262c8

File tree

2 files changed

+12
-8
lines changed

2 files changed

+12
-8
lines changed

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

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,7 @@ public FirebaseApp getApp() {
289289
}
290290

291291
/**
292-
* Configures Indexing for local query execution. Any previous index configuration is overridden.
292+
* Configures indexing for local query execution. Any previous index configuration is overridden.
293293
* The Task resolves once the index configuration has been persisted.
294294
*
295295
* <p>The index entries themselves are created asynchronously. You can continue to use queries
@@ -307,10 +307,14 @@ public FirebaseApp getApp() {
307307
Task<Void> setIndexConfiguration(String json) {
308308
ensureClientConfigured();
309309

310+
if (!settings.isPersistenceEnabled()) {
311+
throw new IllegalStateException("Cannot enable indexes when persistence is disabled");
312+
}
313+
310314
// Preconditions.checkState(BuildConfig.ENABLE_INDEXING, "Indexing support is not yet
311315
// available.");
312316

313-
List<FieldIndex> parsedIndices = new ArrayList<>();
317+
List<FieldIndex> parsedIndexes = new ArrayList<>();
314318

315319
// See https://firebase.google.com/docs/reference/firestore/indexes/#json_format for the
316320
// format of the index definition. Unlike the backend, the SDK does not distinguish between
@@ -320,9 +324,9 @@ Task<Void> setIndexConfiguration(String json) {
320324
JSONObject jsonObject = new JSONObject(json);
321325

322326
if (jsonObject.has("indexes")) {
323-
JSONArray indices = jsonObject.getJSONArray("indexes");
324-
for (int i = 0; i < indices.length(); ++i) {
325-
JSONObject definition = indices.getJSONObject(i);
327+
JSONArray indexes = jsonObject.getJSONArray("indexes");
328+
for (int i = 0; i < indexes.length(); ++i) {
329+
JSONObject definition = indexes.getJSONObject(i);
326330
String collectionGroup = definition.getString("collectionGroup");
327331
List<FieldIndex.Segment> segments = new ArrayList<>();
328332

@@ -340,7 +344,7 @@ Task<Void> setIndexConfiguration(String json) {
340344
}
341345
}
342346

343-
parsedIndices.add(
347+
parsedIndexes.add(
344348
FieldIndex.create(
345349
FieldIndex.UNKNOWN_ID, collectionGroup, segments, FieldIndex.INITIAL_STATE));
346350
}
@@ -349,7 +353,7 @@ Task<Void> setIndexConfiguration(String json) {
349353
throw new IllegalArgumentException("Failed to parse index configuration", e);
350354
}
351355

352-
return client.configureFieldIndexes(parsedIndices);
356+
return client.configureFieldIndexes(parsedIndexes);
353357
}
354358

355359
/**

firebase-firestore/src/main/java/com/google/firebase/firestore/model/FieldIndex.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
* An index definition for field indices in Firestore.
2727
*
2828
* <p>Every index is associated with a collection. The definition contains a list of fields and
29-
* their indexkind (which can be {@link Segment.Kind#ASCENDING}, {@link Segment.Kind#DESCENDING} or
29+
* their index kind (which can be {@link Segment.Kind#ASCENDING}, {@link Segment.Kind#DESCENDING} or
3030
* {@link Segment.Kind#CONTAINS}) for ArrayContains/ArrayContainsAny queries.
3131
*
3232
* <p>Unlike the backend, the SDK does not differentiate between collection or collection

0 commit comments

Comments
 (0)