Creating trending feed

Hi, how do I a “trending feed” where sorting algorithm would give weight to document age(timestamp) and likes. So, I’d like to build a feed page where it’d show recent documents with more likes instead of sorting by most liked documents. I might also want to put certain type of document on top within the feed.

Hi @amitava82,

You will have to add some metadata to your records when you’re indexing.

First about the age, the best way is to add a numerical score to show how recent a post is. This way you can define a better granularity. If you use timestamps, a post added a second later would be ranked higher, which probably doesn’t make sense.

For instance, you could define a freshness property with the following value:

+-------+----------------------------+
| Score | Definition                 |
+-------+----------------------------+
| 1     | Less than 24h              |
+-------+----------------------------+
| 2     | Between 1 and 3 days       |
+-------+----------------------------+
| 3     | Between 3 and 7 days       |
+-------+----------------------------+
| 4     | Between 7 days and 1 month |
+-------+----------------------------+
| 5     | Between 1 month and 1 year |
+-------+----------------------------+
| 6     | Over a year                |
+-------+----------------------------+

This could be your first element of custom ranking, then you create something similar for the likes and add it to the custom ranking too.

About sorting by likes, I don’t know what kind of data you have (likes only, up/down vote or 5 stars rating) but I came across this interesting article recently, I think it could be useful.
http://www.evanmiller.org/how-not-to-sort-by-average-rating.html

Otherwise, you can create your own scoring algorithm (which might be similar) and use it as a “sort by” in your ranking formula.

Please note that you’ll need to reindex your data every days or so (depending on your granularity).

I hope I answered your question. Please tell us how you achieved your goal in the end. I think it’s interesting for the community.

Julien

4 Likes

Thanks! I’m planning to use this algo https://medium.com/hacking-and-gonzo/how-hacker-news-ranking-algorithm-works-1d9b0cf2c08d

I did not want to reindex data daily so this algo should work.

1 Like

Hey @amitava82! Do you have a working solution to create a “trending” feed with Algolia?

Daniel

I’ve used decay for this

That means you’re storing a “score” field on your records in Algolia and reindexing it periodically (assuming that your “trending” feed is time-dependent)?