dariopellegrini/StorageDone-iOS

Im Facing an issue while applying query on search text

Najamus opened this issue · 1 comments

There is a way to search or apply like operator on item name with case insensitive

Hello @Najamus.
Thank you for your request.
Unfortunately, like operator is case sensitive, so there is no way to make a case insensitive query at the moment.

By the way, you have different options.

Use a lowercased field

struct Teacher: Codable {
    let id: Int
    let name: String
    let lowercasedName: String
    
    init(id: Int, name: String) {
        self.id = id
        self.name = name
        self.lowercasedName = name.lowercased()
    }
}
...

let teachers: [Teacher] = try database.get("lowercasedName".like("si%")) // Use lowercase-only queries

Use regex

As well the operator "like", regex is case sensitive. Then due to the C++ lower layer regex engine, modifiers like i for regex are not available.
You can still achieve a case-insensitive query using regex text intervals.

// Search for everything that has a name starting with "ang" case insensitive (ex: "Angela", "Angely")
let teachers: [Teacher] = try db.get("name".regex("[aA][nN][gG].*"))

Use the last committed version of StorageDone-iOS

The last committed version of StorageDone-iOS (0.10.5) supports case-insensitive like.

pod 'StorageDone', :git => 'https://github.com/dariopellegrini/StorageDone-iOS.git'
let teachers: [Teacher] = try database.get("name".like("si%", caseInsensitive: true))

Hope this helps.

Thank you.