Search code examples
grailsgrails-orm

Find instance by name where query is any part of its name, Grails


In Java, the string search by its' substring goes like this:

String string = "Madam, I am Adam";
b = string.matches("(?i).*i am.*");

How to find an instance in Grails by name where query is any part of its name?


Solution

  • I think this is what you're looking for

    DomainClass.findByNameIlike("%i am%")
    

    That is a case insensitive search for any record with name containing "I am". This is not an efficient way to query a database, so if your application will experience any kind of load, you should use it sparingly.

    Edit: Documentation