Details
-
Type:
Improvement
-
Status:
Closed
-
Priority:
Major
-
Resolution: Fixed
-
Affects Version/s: None
-
Fix Version/s: 1.3-M1
-
Component/s: Persistence
-
Labels:None
Description
Currently the standard way to do case-insensitive searches is to use Ilike but that can have unexpected behavior when the input string has an underscore. Underscores are treated as single-character wildcards, so you'll get extra hits if you use ilike just for its case-insensitive search and not for its substring or wildcard feature.
Hibernate's SimpleExpression (used in eq()) has an ignoreCase() method that could be exposed with an optional 3rd parameter to the criteria builder's eq() method, e.g.
DomainClass.createCriteria().list {
eq('name', name, true)
}
for case-insensitive and
DomainClass.createCriteria().list {
eq('name', name)
}
for case-sensitive. Since it'd be optional it's backwards-compatible. Another option would be for the 3rd parameter to be a Map to make it more clear:
DomainClass.createCriteria().list {
eq('name', name, [ignoreCase: true])
}
To see this create a domain class with a String field 'name'
class Test {
String name
}
then run this and the finder will return the instance you just saved:
def t = new Test(name: 'fooxbar').save()
Test.findByNameIlike('foo_bar')
Activity
- All
- Comments
- Work Log
- History
- Activity
- Git Commits
http://github.com/grails/grails/commit/d3cbbc74ee7f5a609bc607c949df23ed6ebde798