FirebaseUI-Android
provides for indexed queries when using a FirebaseRecyclerAdapter
. That works well when accessing Firebase Realtime DB
data as explained here: https://github.com/firebase/FirebaseUI-Android/blob/master/database/README.md#using-firebaseui-with-indexed-data
But what about accessing Firestore
data? It seems that FirestoreRecyclerAdapter
does not support indexed queries via setIndexedQuery(keyref, dataref, ...
) How can I maybe execute the data query manually inside the RecyclerView
?
UPDATE: several people have claimed that Firestore doesn't need indexed queries anymore due to the build-in indexing with makes the schema design much easier than it was with Firebase Realtime DB. Well, I disagree.
Lets say I have a bunch of related items and transactions which I want to query by item and by transaction.
I can't make the transactions a subcollection of items as this would make it impossible to retrieve a list of all transactions. I also can't replicate the item data as redundant fields in each transaction since the data is mutable.
Given these constrains I am stuck with making items and transactions two independent collections which need to be combined again inside the app:
items: {
"item1": {
"name": "some editable label",
[more fields]
}
transactions: {
"trans1": {
"itemid": "item1"
[more fields]
}
"trans2": {
"itemid": "item1"
[more fields]
}
}
FirebaseRecyclerAdapter.setIndexedQuery would have allowed me to retrieve a list of transactions (key) and the corresponding item record with each transaction (data). Firestore indexing, while powerful, does not help in this situation.