How can I use Grails Searchable (lucene) to perform the equivalent Criteria query the most efficient way

88 Views Asked by At

I am searching against a single Domain class, but also trying to allow wildcard queries against 2 String fields, I understand wildcard (first character) queries are supposed to be inefficient however if only against 2 fields, then perhaps that's not so significant.

I'm trying to accomplish what would be the follow as a criteria query..

MyDomain.createCriteria().list {
  and {
    notEqual('deleted',true)
    or {
      ilike('field1','%' + searchText + '%')
      ilike('field2','%' + searchText + '%')
    }
  } 
}

Any suggestions much appreciated, thanks.

1

There are 1 best solutions below

2
On

a lucene query would look like:

-deleted:true +(field1:searchText field2:searchText)