Android Firebase Query to Search user by name or email or phone number

Viewed 150

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

1 Answers

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:

Related