Case-insensitive search
I am using Postgres as database and trying to search for records but it is currently case-sensitive. How can I do the case-insensitive search e.g "Allen" vs "allen" should return same results:
var query = new Query<Table>()
..matchOn.name = whereBeginsWith(params["q"])
..fetchLimit = 10;
You have a few options, you could store and search all of you data in lowercase which is what I do with email addresses. Or you could make a custom predicate, in your case the query would be:
var query = new Query<Table>() ..predicate = new QueryPredicate("name ILIKE @q", {"q" : params["q"]}) ..fetchLimit = 10;
Keep in mind that ILIKE is not a standard SQL operator and does not use indexes.
Or you could do:
var query = new Query<Table>() ..predicate = new QueryPredicate("LOWER(name) = @q", {"q" : params["q"].toLowerCase()}) ..fetchLimit = 10;
I think that would be better actually.
In 2.0, any matcher that can be used for a string has a caseSensitive optional parameter.
var query = new Query<Table>()
..where.name = whereBeginsWith(params["q"], caseSensitive: false);
If you're still using 1.0, I very much suggest moving to 2.0. Otherwise, Alex's advice should work.
Oh I didn't know that was an option now, very cool!