Grails searchable component option

105 Views Asked by At

Where are two domains

class State {
  String name

  static searchable = {
    only: 'name'
  }
}

class Region {
  State state
  String name

  static searchable = {
    state component: true
    only: 'name'
  }
}

I want to find only regions by region name or all regions of state by state name. States should not be in search result.

How I have to change the code?
PS I know how to find objects by gorm. I wrote just simple example of code. I need lucene for featured search

1

There are 1 best solutions below

3
On

Region by region name In SearchableService

def search(String state){
 def stateSearch = State.findByName(region);
 return stateSearch
 }

Find all region of state by state In searchableService

def regionSearch(String region, String state){
 def state = state.findByName(state);
 def region = Region.findByState(state);
return return
}

Hopefully this work.If not, please paste your code in the service.