Skip to content Skip to sidebar Skip to footer

How To Implement The Accent/diacritic Insensitive Search In Sqlite?

Is there a way to do an accent/diacritic insensitive search in sqlite? Googling, I've found this, but I sincerely don't know how to create my 'collation function' in C#. I'm trying

Solution 1:

If you are using System.Data.Sqlite you can use a custom collation sequence and modify it for your needs ... an example:

///<summary>/// User-defined collating sequence using the current UI culture.///</summary>
[SQLiteFunction(Name = "MYSEQUENCE", FuncType = FunctionType.Collation)]
classMySequence : SQLiteFunction
{
  publicoverrideintCompare(string param1, string param2)
  {
    return String.Compare(param1, param2, true);
  }
}

Your SQL query to use the custom collation sequence above might look like this: SELECT * FROM MyTable ORDER BY MyChineseColumn COLLATE MYSEQUENCE DESC

(source: http://sqlite.phxsoftware.com/forums/p/862/3779.aspx#3779)

You just can set collation at table creation and build indices on that column. But remember, you won't be able to access table from other sqlite engine where collation not defined.

Solution 2:

While it's possible to write your own collation, that might easily be slower than using a suitable system-supplied one -- doesn't SQL_Latin1_General_CP1_CI_AS serve your needs, for example? If it does, just use suitable COLLATE clauses (be that on your SELECT or CREATE TABLE queries...) and you should be all set.

Post a Comment for "How To Implement The Accent/diacritic Insensitive Search In Sqlite?"