开发者

Grails Searchable return unique or distinct results

I'm doing a search query on Grails using searchable, but I want to return only distinct results.

years = House.searchEvery('(house_type:"condo")', [sort: 'house_year', order: 'desc'])

How do I make the 开发者_开发问答house_year unique/distinct, or do I need to just parse it myself?


If you want to eliminate duplicates from the results (and in this case a duplicate is considered an object that has the same house_year value), you can use the unique method Groovy adds to Collection

years = House.searchEvery('(house_type:"condo")', [sort: 'house_year', order: 'desc'])
def uniqueYears = years.unique {it.house_year}


obviously there is no simple way to do this with the help of the searchable plugin. after searching for your term you can filtering you result set by your own. in your case i would try to use a regular grails criteria or a hql query. e.g.

House.createCriteria.listDistinct {
   order("house_year", "desc")
   eq("house_type", "condo")
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜