2

we are using grails 2.1.1 and grails searchable-plugin 0.6.4.

We want to search a domain with belongsTo association using searchable.

Suppose we have a domain

class A {
  static belongsTo= [b:B]
}

Now To Access A with b instance we will write criteria as

A.createCriteria.list{
   eq('b',B.get(1))
}

Now how to write similar query with searchable Query Builder.

Wasim
  • 896
  • 7
  • 24

1 Answers1

0

Take a look at the code below (class User has the same relationship as A and B). I have used this way to change the behavior of the default search:

def searchResult = searchableService.search({
  must {
      queryString(params.q)
      must(term('deleted', "false"))
      must(term('status', STATUS_NEW))
      if (loggedUser){
          must(term('User.settings.countryCode', loggedUser.countryCode))
      }
  }
}, params, escape: false, max: 50)

Notice that the objects must be marked as searchable. Above coding is working fine to me. Please refer to Searchable Plugin Documentation for further information.

André Diniz
  • 306
  • 3
  • 15