]> Untitled Git - lemmy.git/blob - docs/src/about_ranking.md
Merge pull request 'Add logging to find bug (ref #1283)' (#146) from debug-1283 into...
[lemmy.git] / docs / src / about_ranking.md
1 # Trending / Hot / Best Sorting algorithm
2
3 An expected feature in link aggregators is a kind of "Trending" sort which shows users a mixture of new posts / comments and popular ones, making for a display order which highlights the most currently active parts of the site / thread.  This keeps the experience fresh and makes sure the site stays moving.  Various flaws can be found in the ways that popular link aggregators like Reddit have implemented "Hot" or "Trending" sorts, so Lemmy has its own algorithm.
4
5 ## Goals and Considerations
6 - During the day, new posts and comments should be near the top, so they can be voted on.
7 - After a day or so, the time factor should go away.
8 - Use a log scale, since votes tend to snowball, and so the first 10 votes are just as important as the next hundred.
9
10 | Reddit | Hacker News | Lemmy |
11 |-|-|-|
12 | Does not take the lifetime of the thread into account, [giving early comments an overwhelming advantage over later ones,](https://minimaxir.com/2016/11/first-comment/) with the effect being even worse in small communities. New comments pool at the bottom of the thread, effectively killing off discussion and making each thread a race to comment early.  This lowers the quality of conversation and rewards comments that are repetitive and spammy. | While far superior to Reddit's implementation for its decay of scores over time, [Hacker News' ranking algorithm](https://medium.com/hacking-and-gonzo/how-hacker-news-ranking-algorithm-works-1d9b0cf2c08d) does not use a logarithmic scale for scores. | Counterbalances the snowballing effect of votes over time with a logarithmic scale.  Negates the inherent advantage of early comments while still ensuring that votes still matter in the long-term, not nuking older popular comments. |
13
14 ## Additional Details
15 ```
16 Rank = ScaleFactor * log(Max(1, 3 + Score)) / (Time + 2)^Gravity
17
18 Score = Upvotes - Downvotes
19 Time = time since submission (in hours)
20 Gravity = Decay gravity, 1.8 is default
21 ```
22 - Lemmy uses the same `Rank` algorithm above, in two sorts: `Active`, and `Hot`.
23   - `Active` uses the post votes, and latest comment time (limited to two days).
24   - `Hot` uses the post votes, and the post published time.
25 - Use Max(1, score) to make sure all comments are affected by time decay.
26 - Add 3 to the score, so that everything that has less than 3 downvotes will seem new. Otherwise all new comments would stay at zero, near the bottom.
27 - The sign and abs of the score are necessary for dealing with the log of negative scores.
28 - A scale factor of 10k gets the rank in integer form.
29
30 A plot of rank over 24 hours, of scores of 1, 5, 10, 100, 1000, with a scale factor of 10k.
31
32 ![](https://raw.githubusercontent.com/LemmyNet/lemmy/main/docs/img/rank_algorithm.png)