title: Popularity decay algorithm for popular website posts
body: <p>I'm looking for an algorithm to sort website results by popularity.. like Reddit's so the older a post the less power it's votes/score has. </p>
  
  <p>Here is the generally accepted solution as used by reddit:</p>
  
  <pre><code>t = (time of entry post) - (Dec 8, 2005)
  x = upvotes - downvotes
  
  y = {1 if x &gt; 0, 0 if x = 0, -1 if x &lt; 0)
  z = {1 if x &lt; 1, otherwise x}
  
  rank = log(z) + (y * t)/45000
  </code></pre>
  
  <p>I've been over Reddit's algorithm and although it will fit for one situation, what I really need is two algorithms, one for Popular posts and another for Upcoming posts:</p>
  
  <ul>
  <li>Popular Posts</li>
  <li>Upcoming Posts</li>
  </ul>
  
  <p>Popular will decay slower, giving more weight to slightly older posts where Upcoming posts will focus more on popular posts today, dropping off sharply after N hours/days/etc.</p>
  
  <p>I'm writing this using Sphinx expressions so I can't write a hugly complicated algo and I only have access to the following functions:</p>
  
  <p><a href="http://sphinxsearch.com/docs/current.html#numeric-functions">http://sphinxsearch.com/docs/current.html#numeric-functions</a></p>
  
  <p>So I have the following data per post:</p>
  
  <ul>
  <li>Post age in seconds</li>
  <li>Post score</li>
  </ul>
  
  <p>Here is my current solution:</p>
  
  <pre><code>Exponent = 0.01 (Popular), 0.5 (Upcoming)
  SecondsSincePublised = abs(CurTimeInSecondsSinceDate-PubTimeInSecondsSinceDate)
  Rank = (log10(PostScore)*10000) / pow(SecondsSincePublised,Exponent) 
  </code></pre>
  
  <p>Although this solution does work its not ideal. A new and popular post in the last couple of hours often ranks high in both popular and upcoming which is not really what I want.</p>
  
  <p>Can anyone suggest another algorithm that I can modify an exponent component to adjust the decay?</p>