Applying Word Stemming in Searchview for Fetch Data from Firebase Database

Applying Word Stemming in SearchView for fetch data from Firebase database

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.

How to filter FirebaseRecyclerOptions with SearchBar

I needed a query indeed as @Black Mamba said. I used something like this:

Query query;
if(!(searchTxt.isEmpty())) {
query = Ref.orderByChild("Surname").startAt(search).endAt(search + "\uf8ff");
}
else{
query = Ref;
}

and the setOnQueryTextListener:

if (searchBar != null) {
searchBar.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
@Override
public boolean onQueryTextSubmit(String query) {
return false;
}

@Override
public boolean onQueryTextChange(String newText) {
firebaseSearch(newText);
return true;
}
});

The firebaseSearch Method retrieves the data from the database.



Related Topics



Leave a reply



Submit