Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Vietnamese Unicode Text Search in SQLite

I am planning to write an iOS app which uses SQLite as the backend. My database contains Vietnamese text such as "Hải Sơn". The users, being used to Google search, want to enter a search term like "hai son" in order to find the text above. I tried the following query:

SELECT * FROM towns WHERE title LIKE '%hai son%';

And I got 0 record. How do I make this to work? I know that Google and other search engines handle this case, so it can be done. I also don't want to make my users type the Vietnamese text with complete diacritical marks because not all the users know how to do so.

Update

I looked at the sqlite3 documentation and looks like there are only three valid collation sequences: BINARY, NOCASE, and RTRIM. Am I missing something?.

More info

My table was created with:

CREATE TABLE towns ( sid INTEGER PRIMARY KEY NOT NULL, title TEXT )

So far, I only used the sqlite3 command line to create the database, table, and import text from a CSV file.

My sqlite3 is at version 3.7.12

Update 2

Alias gave me an idea: to create my own collating sequence. I will post a follow up if it works.

like image 627
Hai Vu Avatar asked Jun 09 '13 06:06

Hai Vu


1 Answers

Try this:

SELECT * FROM towns WHERE title COLLATE UTF8CI LIKE '%hai son%';

Related to answer found here: How do I convert a column to ASCII on the fly without saving to check for matches with an external ASCII string?

like image 117
Aiias Avatar answered Oct 19 '22 13:10

Aiias