1

I have successfully implemented a search feature in my App.

This is the query i use for searching users by username:

Query query = firebaseDatabase.getReference().child("users").orderByChild("username").startAt(s).endAt(s + "~");

Where '~' is the last character in the ASCII alphabet.

In this way I'm able to search users in a case sensitive way.

Is there a way to make a search not case sensitive?

Bronx
  • 4,480
  • 4
  • 34
  • 44
  • 2
    There is currently no way to do case-insensitive searches in Firebase. You best bet would be to store only lowercase data. http://stackoverflow.com/questions/38590937/firebase-query-methods-startat-taking-case-sensitive-parameters – Frank van Puffelen Oct 15 '16 at 11:40
  • Yes, currently i'm storing only lowercase usernames, i hoped there was some hack way to handle this – Bronx Oct 15 '16 at 11:48
  • The problem is that uppercase and lowercase characters are not consecutive. So you'd have to query to separate ranges, or ignore part of your results. As usual in NoSQL: it is a lot simpler if you store your data in a format that allows the queries you want. Case-insensitive queries -> case insensitive data – Frank van Puffelen Oct 15 '16 at 12:03
  • So the best approach would be to store 2 records, one for the real username and the other one for the username in lower case and search only for the second one? – Bronx Oct 15 '16 at 12:06
  • I would keep a separate list of `usernamesForSearch`, where you can do all manipulation for making the data searchable. – Frank van Puffelen Oct 15 '16 at 14:58
  • Ok thanks, i will try it – Bronx Oct 15 '16 at 15:41
  • 2
    why FB didnt implement the most basic thing? – SuperUberDuper Jul 11 '20 at 10:23

0 Answers0