0

I need to fetch list of users from Firebase database using SeachView or search dialog and I think word stemming will be best for my app.

Not asking for code but please tell me the alorigthm for it.

Alex Mamo
  • 130,605
  • 17
  • 163
  • 193
parag pawar
  • 193
  • 3
  • 13

1 Answers1

2

To achieve what you want, you need to execute a query which should look like this:

DatabaseReference rootRef = FirebaseDatabase.getInstance().getReference();
DatabaseReference usersRef = rootRef.child("users");
Query query = usersRef.orderByChild("name").equalTo(newText);

So everytime you create a search you should return a new query. So according to this, every time you want to filter on a new condition, you will need to:

  1. Create a new query based on the new filter:

    Query query = usersRef.orderByChild("name").equalTo(newText);
    
  2. Attach a listener to this new created query.

  3. Create a new adapter with the results of this new created query, or update the existing one using notifydatasetchanged() method.

Alex Mamo
  • 130,605
  • 17
  • 163
  • 193
  • So by using equalTo() does firebase gives a list of data or a single item which is equal to newText ? – parag pawar Jun 04 '18 at 14:19
  • 1
    Depending on what the query returns. If it finds a single user name, a single user name will be returned otherwise it will return as many as it finds. If the user name is unique, a single user named will be returned. – Alex Mamo Jun 04 '18 at 14:21