gpt4 book ai didi

Android,变音符号不敏感 SQLite 搜索

转载 作者:IT老高 更新时间:2023-10-28 23:15:43 24 4
gpt4 key购买 nike

我正在尝试在 android 中查询一个 SQLite 数据库,其中带有重音符号的法语字符应该像普通拉丁字符一样处理,例如:

SELECT * FROM x WHERE y LIKE %cafe%

应该返回

café, câfè, ...

我已经用谷歌搜索了一整天,并阅读了有关 stackoverflow 的所有帖子。无法向包含规范化标题的表添加列,因为数据库是从服务器获取并由第三方维护的。

使用其他帖子中提到的排序规则,例如

Latin1_general_CI_AI

也没有选择,因为 SQLite 仅支持 3(在 android 5 中)对我没有帮助的排序规则。

将android中的数据库设置为

Locale.FRENCH

并使用排序规则

COLLATE LOCALIZED

也不行。

我知道 iOS (DiacriticInsensitiveSearch) 中有一些标志会自动执行此操作,所以我希望类似的东西也可用于 android。

有什么想法吗?提前致谢!

最佳答案

The possibility to add a column to the table that includes normalized titles is no option, because the database is fetched from a server and maintained by a third party.

您可以使用规范化列和原始表的外键创建单独的表。我认为这是您在 android 上使用 sqlite 的唯一选择。

或者如果你能以某种方式创建用户定义的函数remove_diacritics,那么你会选择这样的:

SELECT * FROM x WHERE remove_diacritics(lower(y)) 
LIKE remove_diacritics(lower(%cafe%))

但要注意 x.y 上的索引不会被使用。您也可能不需要 lower。但据我所知,如果可能的话,在 sqlite 上创建函数并不是那么容易。

关于Android,变音符号不敏感 SQLite 搜索,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12624078/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com