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.n开发者_StackOverflowame' 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.
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!
精彩评论