【问题标题】:Like does not work with Russian symbols? (Swift, SQLite)喜欢不适用于俄罗斯符号吗? (斯威夫特,SQLite)
【发布时间】:2023-03-15 21:25:02
【问题描述】:

我对小写字符串和俄语符号使用 like,但 LOWER 不会在查询中将它们转换为小写。我试图创建自己的函数,但它对我不起作用。如何解决这个问题?

研究了SQLite的文档,了解到需要连接ICU库。如何在这个插件中做到这一点?

库:stephencelis/SQLite.swift (https://github.com/stephencelis/SQLite.swift) 感谢您的帮助。

// in name value: ПРИВЕТ from database
let search_name = "Привет"
user.filter(name.lowercaseString.like("%" + search_name.lowercased() + "%"))

【问题讨论】:

    标签: swift sqlite sqlite.swift


    【解决方案1】:

    SQLite LOWER 仅适用于 ASCII。如果您想让俄语(或除 ASCII 以外的任何其他符号)不区分大小写,请使用 FTS3/FTS4 https://www.sqlite.org/fts3.html(或 FTS5 https://www.sqlite.org/fts5.html)。

    SQLite.swift 有对应的全文搜索模块https://github.com/stephencelis/SQLite.swift/blob/master/Documentation/Index.md#full-text-search

    要在现有数据库的项目中使用它,您应该通过 FTS 模块连接到虚拟表并使用 .match 过滤查询

        // CREATE VIRTUAL TABLE "table" USING fts4("row0", "row1"), if not exists
        try db.run(table.create(.FTS4(row0, row1), ifNotExists: true))
         
        // SELECT * FROM "table" WHERE "row0" MATCH 'textToMatch*'      
        try db.prepare(table.filter(row0.match("\(textToMatch)*")))
        
        // SELECT * FROM "table" WHERE "any row" MATCH 'textToMatch*' 
        try db.prepare(table.match("\(textToMatch)*")))
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-07-22
      • 2017-03-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-09-17
      • 2016-02-08
      • 2017-11-13
      相关资源
      最近更新 更多