2

I am using following query to search user by name

public void filterSearch(String searchInput) {
     Query searchQuery = mDatabaseReference.orderByChild("name").startAt(searchInput).endAt(searchInput + "\uf8ff");
     ....
}

But now, I want to know, how can I use query to search user by name or email or phone number

FYI: I'm using FirebaseRecyclerAdapter

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
Android
  • 1,529
  • 1
  • 12
  • 27
  • Do you want to query by the other properties in the same query? – Alex Mamo May 27 '20 at 09:37
  • In same query that will be more useful, otherwise share your suggestions as I have kept single EditText to accept name or email or phone number from user @AlexMamo – Android May 27 '20 at 09:48

1 Answers1

1

What you are searching for is a query using a logical OR:

.orderByChild("name").startAt(searchInput).endAt(searchInput + "\uf8ff") ||
.orderByChild("email").startAt(searchInput).endAt(searchInput + "\uf8ff") ||
.orderByChild("phone number").startAt(searchInput).endAt(searchInput + "\uf8ff")

Which unfortunately is not possible in Firebase Realtime Database because it has no concept of that kind of query. To solve this, you'll have to query each type of thing separately and merge them together in your code as needed.

You can also check, @FrankvanPuffelen's answer from the following post:

Alex Mamo
  • 130,605
  • 17
  • 163
  • 193
  • why firebase missed such an important concept, anyways do you have any idea on this:: https://stackoverflow.com/questions/62037592/firebase-on-update-data-layout-getting-called – Android May 27 '20 at 10:33
  • I'll take a look and if I'll know the answer, I'll write to you. – Alex Mamo May 27 '20 at 10:34