OGeek|极客世界-中国程序员成长平台

标题: iOS - 如何使用 SQLite.swift 进行变音符号不敏感搜索? [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-13 12:13
标题: iOS - 如何使用 SQLite.swift 进行变音符号不敏感搜索?

我正在使用 SQLite.swift。 有什么方法可以在 SQLite 中执行不区分变音符号的 LIKE 查询?例如,这个查询:

SELECT * FROM users WHERE name LIKE "thu%"

会返回:

thử
thu
thư
etc.



Best Answer-推荐答案


来自 the documentation :

We can create custom collating sequences by calling createCollation on a database connection.

try db.createCollation("NODIACRITIC") { lhs, rhs in
    return lhs.compare(rhs, options: .DiacriticInsensitiveSearch)
}

We can reference a custom collation using the Custom member of the Collation enumeration.

restaurants.order(collate(.Custom("NODIACRITIC"), name))
// SELECT * FROM "restaurants" ORDER BY "name" COLLATE "NODIACRITIC"

在您的情况下,您可以在之后执行以下查询:

SELECT * FROM users WHERE name COLLATE NODIACRITIC LIKE 'thu%'

关于iOS - 如何使用 SQLite.swift 进行变音符号不敏感搜索?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34051832/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://sqlite.in/) Powered by Discuz! X3.4