I am fairly new to Android app development. I have created a simple search query that searches my firebase database by name (see code below):
private void firebaseEventSearch(String name) {
//query to search database based on text in textbox - made case insensitive
Query eventSearchQuery = eventRef.orderByChild("name").startAt(name.toUpperCase()).endAt(name.toLowerCase() + "\uf8ff");
eventSearchQuery.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
for (DataSnapshot eventSnapshot : dataSnapshot.getChildren()) {
Event event = eventSnapshot.getValue(Event.class);
events.add(event);
}
adapter.notifyDataSetChanged();
}
@Override
public void onCancelled(@NonNull DatabaseError databaseError) {
}
});
}
It works fine for the most part, however, it will display all database results when I type in the letters "A" or "B" - the search does not work for these two letters. Also, if I type in a search string where the first letter matches a database entry, it will display this database item, even if the rest of the string does not match it.
I would really appreciate if anyone could help me understand why this search query is not working properly.