-1

I need to rank a number of posts by their updated_at timestamp but I need the rank to have some sort of exponential decay after the post has been updated 6 hours after created_at until 2 weeks at which point it breaks even and doesn't change rank.

When the post is created, updated_at is set to the timestamp as created_at to kick-off sorting.

I looked at Hot content algorithm / score with time decay which is along the lines of what I'm looking for but I need the rank to have a precision similar to the updated_at timestamp.

The reason I need this is so that posts which were created a while back yet updated recently won't be shown higher than posts that were recently created.

Community
  • 1
  • 1
paulkon
  • 1,755
  • 2
  • 20
  • 34
  • 2
    I think, once you've stated this question clearly enough for someone to answer it correctly, you'll have answered it correctly. – jthill Nov 28 '13 at 01:58
  • How should I further clarify it? – paulkon Nov 28 '13 at 02:02
  • What do you mean by "drop off" the rank? So you only want to rank first all that were created in the past 6 hours based on `updated_at`, then after that you rank the rest based on `created_at` field? – justhalf Nov 28 '13 at 02:07
  • what kind of rank has a precision? drop off how much, in what range? How should a file updated after a longer interval be ranked against a file created later, and what procedure did you use to arrive at that? – jthill Nov 28 '13 at 02:08
  • I think by precision he is referring to online ranking algorithm, where the time keeps ticking and the ranks need to be updated every millisecond (or every short amount of time) – justhalf Nov 28 '13 at 02:09
  • Essentially, the posts are sorted by their `updated_at` timestamp but I need to push them down lower in the post results as the are updated later and later than their creation time so that newly created posts can show up on top. – paulkon Nov 28 '13 at 02:12

1 Answers1

1

Do you really need a time-exponential-decay score? That seems rather unlikely. Instead, you want to sort by a modified updated_at:

def updated_val(item):
    if(item.updated_at - item.created_at > 6 hours)
        return item.created_at + 6 hours
    else
        return item.updated_at

If the item has been edited within 6 hours we return the unmodified updated_at. However, if the item has been edited after six hours, we return simply the last valid updated_at value, which would be created_at + 6 hours.

If you have something like an additional score function, you can simply plug it into this solution:

def updated_val_scored(item):
    if(item.updated_at - item.created_at > 6 hours)
        return score(item.created_at + 6 hours)
    else
        return score(item.updated_at)
Zeta
  • 103,620
  • 13
  • 194
  • 236
  • The post gets updated only when someone comments on it. For that case I would still like it to show up on the first page but pulled down based on how long the original post was created (edited or not). – paulkon Nov 28 '13 at 07:42
  • @PaulKonova: So you want to sort by creation time, but show only on the front page if the post has been edited in the last six hours? Then your current question isn't really complete. Add some examples/scenarios. – Zeta Nov 28 '13 at 07:50