如何在Sqlite中实现口音/变音符号不敏感搜索? [英] How to implement the accent/diacritic insensitive search in Sqlite?

查看:185
本文介绍了如何在Sqlite中实现口音/变音符号不敏感搜索?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法在sqlite中做重音符号/区分音符不敏感搜索?

Is there a way to do an accent/diacritic insensitive search in sqlite?

Google搜索,我发现了,但我真的不知道如何在C#中创建我的排序函数。我正在尝试为Sqlite创建pt-br排序规则...

Googling, I've found this, but I sincerely don't know how to create my "collation function" in C#. I'm trying create the pt-br collation for Sqlite...

推荐答案

如果您使用System.Data.Sqlite可以使用自定义的排序规则序列并根据您的需要修改它...例如:

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)]
class MySequence : SQLiteFunction
{
  public override int Compare(string param1, string param2)
  {
    return String.Compare(param1, param2, true);
  }
}

您的SQL查询要使用上述自定义归类序列看起来像这样:
SELECT * FROM MyTable ORDER BY MyChineseColumn COLLATE MYSEQUENCE DESC

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

(来源: http://sqlite.phxsoftware.com/forums/p/862/3779.aspx#3779

您只需在表创建时设置排序规则,并在该列上构建索引。
但是请记住,你不能从其他sqlite引擎访问表,其中排序规则未定义。

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.

这篇关于如何在Sqlite中实现口音/变音符号不敏感搜索?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆