Reputation: 4139
i have a number of objects in the datastore, thy have a Score value and a creation date.
I would like to get the list of objects orderd, after the hacker news algorithm ,
In sql it whould be something like
(SUM(score) - 1) / POW(TIMESTAMPDIFF(HOUR,p.time_submitted,NOW()) + INTERVAL 2 HOUR, 1.8) DESC LIMIT 100
but how do i do this with the datastore in java? Can i order after a method in the objects? What i want is to sorte like this
Order by : Score = (P-1) / (T+2)^G where,
P = points of an item (and -1 is to negate submitters vote)
T = time since submission (in hours)
G = Gravity, defaults to 1.8 in news.arc
Thanks!
Upvotes: 1
Views: 250
Reputation: 101139
As Dave points out, this doesn't work well at scale in a naive implementation, because it requires a lot of updates, and you can't compute the ranking live if you want it to scale.
There are ways around this, though, and for an example of a similar ranking scheme, see my post Most Popular Metrics in App Engine. In a nutshell: by updating the decay value every time you record a vote, and updating stale entities every few hours, you can minimize the amount of redundant work done while still keeping results mostly accurate.
Upvotes: 1
Reputation: 24956
Ranking schemes based on decay are really tempting, because they have several knobs to tune, but I've not yet seen one that scales well on App Engine. Decay involves touching lots of entities.
In Just Overheard It, Joe Gregorio presents a different idea for ranking that does scale well. The gist is that every day inherently ranks more than the day before, and votes get added on date rank of an entry. Think of it as building in decay by tilting the ranking space.
Upvotes: 1