开发者

Grails Searchable return unique or distinct results

开发者 https://www.devze.com 2023-03-11 06:52 出处:网络
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\'])

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

精彩评论

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

关注公众号