How to limit the search to the value of a component field using the grails graphics plugin

Using the grails graphics plugin, I would like to search all products in a specific category using the query builder, for example:

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

Using 'category.name' returns: Could not find a match for aliases [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? Thank.

+3
source share
1 answer

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!

+4
source

Source: https://habr.com/ru/post/1782506/


All Articles