Realm - Search for accented content

0

From what I read, Realm still does not support accentuated terms. I wanted to know if there is any way of querying the Realm data, ignoring the accent. For example, I search for "veterinarian" (without accent) and the realm returns the "vet" (with accent) that is saved in the database.

I know I can grab 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?

    
asked by anonymous 02.11.2017 / 19:26

1 answer

0

I use a function of mine that removes accents from a string. Maybe if you apply this function to the searched term, then play this term to realm solve 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;
    }
    
06.11.2017 / 12:17