I'm creating an autoCompleteTextView
by using data from firestore.
My firestore cloud is built as follows:
Where for example I have 2 UserNames:
UserName 1 = "he is ok, ben"
UserName 2 = "ben is ok"
In order to autoComplete the names, I search the cloud by using:
db.collection( "Names" )
.whereGreaterThanOrEqualTo("UserName", s.toString() ).whereLessThanOrEqualTo( "UserName", s.toString() + "\uF7FF" ).get()
.addOnCompleteListener( new OnCompleteListener<QuerySnapshot>() {
@Override
public void onComplete(@NonNull Task<QuerySnapshot> task) {
if (task.isSuccessful()) {
for (QueryDocumentSnapshot document : task.getResult()) {
String name = document.getString( "UserName" );
names.add( name );
}
}
}
} );
Now, if for example I type "be"
, the code above works good and finds the result for UserName 2 (ben is ok
) but it wont find the first one since the UserName doesnt start with ben.
How can I make sure that it finds any UserName as long as "be" is a substring?
I tried also to change the data into array that will look as:
and to perform whereArrayContains
. Again, this solution works only if I typed a whole word from the array (for example if I wrote be
I got no result, and only if I wrote ben
it found since ben is a full part of the array object).
Is there any way I can find a substring from either a string or an array no matter where it appears in the sentence?