Q:

Mongoid order_by a rounded value

I’d like to sort by date then by rating but I’d like the date rounded to the nearest half year (or some time span).
This would have the effect of showing most recent 6 months ordered by rating, then next most recent 6 months ordered by rating. 
Currently I have a scope:
scope :newer_popular, order_by(:release_date => :desc, :avg_rating => :desc).where(:release_date.ne => 0, :avg_rating.ne => 0 )

Obviously doesn't do it, this treats the release_date (a Date object) as a continuous ordering so only objects that happened to have been released at exactly the same time are actually ordered by rating.
Is there a way to do this faceted/grouped/rounded ordering in Mongoid?

A:

I would order just by rating, and use a where criteria for release date:
where(:release_date.gte => 6.months.ago.utc).order_by(:avg_rating => :desc)

For the next page:
where(:release_date.lt => 6.months.ago.utc, :release_date.gte => 12.months.ago.utc).order_by(:avg_rating => :desc)

Or something like that.

