Micor
Micor

Reputation: 1542

How to restrict search to component's field value with grails searchable plugin

Using grails searchable plugin, I would like to search for all products within a specific category using a query builder like:

Products.search {
  must(queryString(params.q))
  must(term('??????','Food'))  
}

Using 'category.name' returns: Failed to find mapping for alias [category] and path [category.name]

class Product {    
  String name
  String desc
  Category category

  static searchable = {
    category component: true
  }
}

class Category {      
  String name

  static hasMany = [products: Product]

  static searchable = true     
}

Any ideas? Thanks.

Upvotes: 3

Views: 1107

Answers (1)

Maricel
Maricel

Reputation: 2089

I think you can do something like:

def results = Product.search {
  must(term('$/Product/category/name', params.categoryName))
  must(queryString(params.q))
}

Hope this helps!

Upvotes: 4

Related Questions