Android Question Searchview Question

tufanv

Expert
Licensed User
Hello,

I am using searchview in some of my projects. I have a small problem with it. If the word searched is turkısh, searchview can't filter turkish because of the ı-i difference. Or for example, We have ş,ç,ö,ğ in our alphabet and sometimes users make searches using these chars but the searchview vant find them because they used ş instead of s or they used ö instead of o . Is there a solution for this?

Thanks
 

Erel

Administrator
Staff member
Licensed User
There is a normalization step that happens when the index is built and when the user searches. Normalization means that the raw input is "normalized" in some way. In SearchView it is done by calling ToLowerCase.

The issue with the Turkish i can be solved easily by changing ToLowerCase with ToUpperCase.

You can also solve the issue with umlauts with a more complex normalization method:
B4X:
Sub RemoveAccents(s As String) As String
    s = s.ToUpperCase
    Dim normalizer As JavaObject
    normalizer.InitializeStatic("java.text.Normalizer")
    Dim n As String = normalizer.RunMethod("normalize", Array As Object(s, "NFD"))
    Dim sb As StringBuilder
    sb.Initialize
    For i = 0 To n.Length - 1
        If Regex.IsMatch("\p{InCombiningDiacriticalMarks}", n.CharAt(i)) = False  Then
            sb.Append(n.CharAt(i))
        End If
    Next
    Return sb.ToString
End Sub
You will need to use it instead of every occurrence of ToLowerCase.
 
Upvote 0
Top