iPhone 应用程序中的表查询

发布于 2024-07-24 23:34:24 字数 403 浏览 7 评论 0原文

我有一个表格视图(链接到数据库)和一个搜索栏。 当我在搜索栏中输入内容时,我会在数据库中进行快速搜索并在输入时显示结果。

查询如下所示:

SELECT * FROM MyTable WHERE name LIKE '%NAME%'

只要我仅使用 ASCII 字符,一切都会正常工作。 我想要的是输入 ASCII 字符并用变音符号匹配它们的等价字符。 例如,如果我输入“Alizee”,我希望它与“Alizee”匹配。

有没有办法使查询区域设置不敏感? 我对 SQL 中的 COLLATE 选项感到红色,但似乎对 SQLite 没有用。我还对 iPhone SDK 3.0 有“本地化排序规则”感到红色,但我找不到任何关于这意味着什么的文档。 。

谢谢。

I have a tableview (linked to a database) and a search bar. When I type something in the search bar, I do a quick search in the database and display the results as I type.

The query looks like this:

SELECT * FROM MyTable WHERE name LIKE '%NAME%'

Everything works fine as long as I use only ASCII characters. What I want is to type ASCII characters and to match their equivalent with diacritics. For instance, if I type "Alizee" I would expect it to match "Alizée".

Is there a way to do make the query locale-insensitive? I've red about the COLLATE option in SQL, but there seems to be of no use with SQLite.I've also red that iPhone SDK 3.0 has "Localized collation" but I was unable to find any documentation about what this means...

Thank you.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

她如夕阳 2024-07-31 23:34:24

有几个选项可以解决此问题:

  1. 替换中的所有重音字符
    在执行之前查询,例如

    <块引用>

    “迷幻药”=> “迷幻”
    “À contre-courant” => “反对派”
    “Tempête” => “坦佩特”
    等等

    但这仅适用于输入,所以
    你不能有重音字符
    数据库本身。 简单的解决方案但是
    远非完美。

  2. 使用第三方库,即 ICU(链接如下)。 但不确定它是否是 iPhone 的最佳选择。

  3. 编写一个或多个自定义 C 函数来进行比较。 更多内容请参见下面的链接。

StackOverflow 上的一些帖子讨论了各种选项:
如何使用指定的区域设置对 sqlite3 中的文本进行排序?
SQLite 的不区分大小写的 UTF-8 字符串排序规则 (C/C++ )
如何在Sqlite中实现重音/变音符号不敏感搜索?

还有一些外部链接:
C/ 中的 SQLite 和本机 UNICODE LIKE 支持C++
sqlite 不区分大小写和重音的搜索

There are a few options for solving this:

  1. Replacing all accented chars in the
    query before executing it, e.g.

    "Psychédélices" => "Psychedelices"
    "À contre-courant" => "A contre-courant"
    "Tempête" => "Tempete"
    etc.

    but this only works for the input so
    you must not have accented chars in
    the database itself. Simple solution but
    far from perfect.

  2. Using a 3rd party library, namely ICU (links below). Not sure if it's the best choice for iPhone though.

  3. Writing one or more custom C functions that will do the comparison. More in the links below.

A few posts here on StackOverflow that discuss the various options:
How to sort text in sqlite3 with specified locale?
Case-insensitive UTF-8 string collation for SQLite (C/C++)
How to implement the accent/diacritic insensitive search in Sqlite?

Also a couple of external links:
SQLite and native UNICODE LIKE support in C/C++
sqlite case and accent insensitive searches

鸠书 2024-07-31 23:34:24

我不确定 SQL,但我认为您绝对可以使用 NSDiacriticInsensitivePredicateOption 来比较内存中的 NSString。

一个例子是一个充满你正在搜索的字符串的 NSArray。 您可以使用 NSDiacriticInsensitivePredicateOption 作为比较选项来迭代比较字符串的数组并显示成功的匹配。

I'm not sure about SQL, but I think you can definitely use the NSDiacriticInsensitivePredicateOption to compare in-memory NSStrings.

An example would be an NSArray full of the strings you're searching over. You could just iterate over the array comparing strings using the NSDiacriticInsensitivePredicateOption as your comparison option and displaying the successful matches.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文