Realm - Search for content with accentuation

Asked

Viewed 66 times

0

From what I’ve read, the Realm is not yet up for accentuation. I wanted to know if there is any way to query the Realm data ignoring the accentuation. For example, I search for "veterinario" (without accent) and the "veterinarian" (with accent) returns me.

I know I can take the whole list and play in an Arraylist, and with it make an algorithm to ignore the accents. However, the database is large and the response time has to be instantaneous leaving this practice unfeasible.

Any suggestions?

1 answer

0


I use a function of mine that removes the accents of a string. Maybe if you apply this function in the searched term, and then play this term for the Real solves the situation:

public static String removerAcentos(String valor) {
        if(valor == null)
            return "";

        String comAcentos = "ÄÅÁÂÀÃäáâàãÉÊËÈéêëèÍÎÏÌíîïìÖÓÔÒÕöóôòõÜÚÛüúûùÇ纪°´`Çô";
        String semAcentos = "AAAAAAaaaaaEEEEeeeeIIIIiiiiOOOOOoooooUUUuuuuCc     Co";
        for (int i = 0; i < comAcentos.length(); i++)
        {
            valor = valor.replace(comAcentos.charAt(i), semAcentos.charAt(i));
        }
        return valor;
    }

Browser other questions tagged

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