0

I try to solve this issue that I have in Firebase. I want to give user the option to search for friends ok, so he start typing friend name or email, and it should find possible results from firebase database. I have implemented easy with only search for either name or email, but for both, how to solve? Multiple query sound messy to me, is possible somehow?

To search with email in user I do this. Works perfectly but cannot search for name..

            Query queryEmail = FirebaseDatabase.getInstance().getReference()
                    .child(LOCATION_USERS)
                    .orderByChild(PROPERTY_EMAIL)
                    .limitToFirst(10)
                    .startAt(text)
                    .endAt(text + "~");

Here is what I mean below, is there a way to achieve this?

enter image description here

KENdi
  • 7,576
  • 2
  • 16
  • 31
  • 1
    Firebase Database queries can only order/filter on a single property. There is no support for an `OR`. But you can likely add additional data to allow the use case, such as a simple "search map" where you keep the UIDs (as values) for each name and email. The structure would work similar to the one in my answer here: https://stackoverflow.com/questions/27207059/firebase-query-double-nested. Also see my answer on categorization queries here: http://stackoverflow.com/questions/40656589/firebase-query-if-child-of-child-contains-a-value – Frank van Puffelen Jun 12 '17 at 14:02

1 Answers1

0

You must use multiple queries. I advise you change your structure to

userUID
  name
  email
  age
  name_lowercase
  email_lowercase

and then convert your query ex: John to john, that way it doesn't matter if the user capitalizes his input or not.

ryan brown
  • 31
  • 1