For small datasets you can use the following code:
ValueEventListener valueEventListener = new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
List<String> list = new ArrayList<>();
for(DataSnapshot ds : dataSnapshot.getChildren()) {
String from = ds.child("from").getValue(String.class);
list.add(from);
}
for(String str : list) {
if(str.contains(searchText)) {
Log.d("TAG", "String found!");
}
}
}
@Override
public void onCancelled(DatabaseError error) {
Log.d("TAG", error.getMessage()); //Never ignore potential errors!
}
};
myRef.addListenerForSingleValueEvent(valueEventListener);
This solution is not recommended for large datasets because you'll need to download the entire node in order to make a search. In this case, Algolia or Elasticsearch are recommended.
If you intend to use Cloud Firestore, I recommend you to see my answer from this post. For more information, I also recommend you see this video.