Skip to content

Instantly share code, notes, and snippets.

@HashNuke
Forked from abitdodgy/hot_algorithm.md
Created June 26, 2014 05:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save HashNuke/904064494eec30648e6c to your computer and use it in GitHub Desktop.
Save HashNuke/904064494eec30648e6c to your computer and use it in GitHub Desktop.

A sorting algorithm for sorting by "hotness", roughly based on Reddit's algorithm with a few tweeks.

scope :order_by_hot, ->
  { order("round((votes_count - 1) / POW(DATE_PART('day', Now() - created_at) * 24 + DATE_PART('hour', Now() - created_at) + 2, 1.5)::numeric, 8) DESC, votes_count DESC") }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment