简体   繁体   中英

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.

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!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM