Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Making a firebase query search NOT case sensitive [duplicate]

I wanna pull information from a Firebase Database but it's a case sensitive query, and i don't want it to be case sensitive, is there a way to make the query NOT case sensitive in Android Studio ,Here is the query code

DatabaseReference SearchRef = (DatabaseReference) FirebaseDatabase.getInstance().getReference().child("Child1").orderByChild("Child2").startAt(searchText).endAt(searchText + "\uf8ff"); // \uf8ff is a white space
    Query Searchquery = Searchref;
    Searchquery.addValueEventListener...
like image 888
captindfru Avatar asked Jun 12 '18 07:06

captindfru


People also ask

Are Firebase queries case sensitive?

David Notik. Ok, so Firebase is case-sensitive so if you're users/Kai is not same as users/kai.

What is uf8ff Firebase?

The character \uf8ff used in the query is a very high code point in the Unicode range (it is a Private Usage Area [PUA] code). Because it is after most regular characters in Unicode, the query matches all values that start with queryText .

How do I find my unique key in Firebase?

You can create a unique key in Firebase database using push() and then add child nodes under that key. Now next time when you come to that activity, first check if parent node exists or not. If the node exists, save parent node key and use it to save new child nodes.

Which method is used to fetch any key from Firebase?

We can use HashMap.


1 Answers

When using Firebase Database, that is the much you get to from orderByChild() function. It returns data either ascending or descending order and you cannot customize your result with extended queries.

However, You can try a something else that may be a bit more expensive. Get all the children you want as an array, saving Child2 and its key. You can then change the string to upper case or lower case and access the desired result using the key.

The reference result would be

FirebaseDatabase.getInstance().getReference("Child1").child(key);

EDIT

To add on your logic, If you want "Dave" or "dave" to return Dave and dave You can edit your query to startAt(text.toUppercase) and endAt(text.toLowerCase+ "\uf8ff"). This will return DAVE, Dave, dave etc

like image 167
Disney Program Avatar answered Nov 10 '22 08:11

Disney Program