0

I want to perform something like:

    firebaseDatabase = FirebaseDatabase.getInstance().getReference().child("resources");
    Query firebaseSearchQuery =firebaseDatabase.child("tags").startAt(text).endAt(text+"\uf8ff");

Find matches with text in every tags's childs values. For me its:"whopper", "burger", "king", "Whopper" enter image description here

How I can query and find matches?

  • Your current data structure makes it easy to find the tags for a resource. It does not however make it easy to find the resources for a tag. To allow that, you'll need to create an additional, inverse data structure that maps from tags back to the resources. For more on this, see https://stackoverflow.com/questions/40656589/firebase-query-if-child-of-child-contains-a-value – Frank van Puffelen Jan 18 '21 at 15:44

2 Answers2

1

Seems like you want to find all children where values contains certain String.

equalTo() Return items equal to the specified key or value depending on the order-by method chosen.

DatabaseReference rootReference = FirebaseDatabase.getInstance().getReference();
DatabaseReference resources01Referense = rootReference.child("01").child("tags");
Query query = resources01Referense.orderByValue().equalTo(text+"\uf8ff");
 

Then query your data

Link to do documentation

0

Your "tags" node is actually a Map, that contains four key-value pairs. Unfortunately, Firebase doesn't provide a way to search into such a structure using "startAt()" and "endAt()", which only works against a property of type String. What you need is some kind of a search feature. Unfortunately, Firebase does not support native indexing or search for text fields in database properties. However, to solve this issue, I recommend you check my answer from the following post:

Alex Mamo
  • 130,605
  • 17
  • 163
  • 193