In Android sqlite, LIKE
and GLOB
ignore both COLLATE LOCALIZED
and COLLATE UNICODE
. However, there is a solution without having to add extra columns to your table. As @asat explains in this answer, you can use GLOB
with a pattern that will replace each letter with all the available alternatives of that letter. In Java:
public static String addTildeOptions(String searchText) {
return searchText.toLowerCase()
.replaceAll("[aáàäâã]", "\\[aáàäâã\\]")
.replaceAll("[eéèëê]", "\\[eéèëê\\]")
.replaceAll("[iíìî]", "\\[iíìî\\]")
.replaceAll("[oóòöôõ]", "\\[oóòöôõ\\]")
.replaceAll("[uúùüû]", "\\[uúùüû\\]")
.replace("*", "[*]")
.replace("?", "[?]");
}
And then (not literally like this, of course):
SELECT * from table WHERE lower(column) GLOB "*addTildeOptions(searchText)*"
This way, a user searching for either Grambu or Grambú will get the search converted into Gramb[uúùüû], returning both results.
It is important to notice that GLOB
ignores COLLATE NOCASE
, that's why I converted everything to lower case both in the function and in the query. Notice also that the lower()
function in sqlite doesn't work on non-ASCII characters - but again those are probably the ones that you are already replacing!
The function also replaces both GLOB
wildcards, *
and ?
, with "escaped" versions.