Case insensitive search Firebase

Asked

Viewed 396 times

0

I’m using Toolbar’s searhcview for searching recyclerview items the search works, but Firebase’s query differentiates between upper and lower case and sharp words. I wish it was Case insensitive search for Firebase.

Ex: I searched the word São Paulo and typed in the search sao paulo.

In recyclerview I would like the word São Paulo to appear with capital letters and also with the.

The way my query is only appears São Paulo if I put in search the word São Paulo.

 Query Q = organizacao.orderByChild("nomeOrganizacao").
 startAt(newText).endAt(newText + "\uf8ff");

inserir a descrição da imagem aqui

1 answer

0

At the moment, Firebase is unable to perform case insensitive searches. But an alternative for you to have the desired result would be: Add a second field that keeps the name of the Organization in lower case:

"01":{
    "nomeOrganizacao":"São Paulo",
    "nomeMinusculo":"são paulo",
    ...
}

And when it’s time to fetch the data, you transform the String that comes from Searchview to lowercase and query through this field:

newText = newText.toLowerCase();
Query Q = organizacao.orderByChild("nomeMinusculo").
 startAt(newText).endAt(newText + "\uf8ff");

Browser other questions tagged

You are not signed in. Login or sign up in order to post.