2
votes

I am wondering how to return specific domain with searchable? For example we have domain A and B. Both domain are searchable and have relationship: A has many B and B belongs to A. Another case A and B have many-to-many relationship.

Now when I search for item, I must always return A item. In my case let say I found matches in B, I need to return all As for each B. Other way around should work as well.

Currently I do a search query is searchable services:

def searchResults = searchableService.search(params.q, params)

Is there a way to get all related A domain for any search results?

Thank you.

1

1 Answers

2
votes

Make both your domains(A & B) searchable and then add DomainObject component:true in searchable properties.

class A{
  String name

  static hasMany = [bclass: B]
  static searchable = {
     bclass component: true
  }
}

class B{
  String color

  static belongsTo= [aclass: A]
  static searchable = true
}

Suppose in B there are some rows with color field value as 'red'

A.search("red") 

will return all the instances of A, which has its child class B with color field value as 'red'