Ayende @ Rahien

My name is Oren Eini
Founder of Hibernating Rhinos LTD and RavenDB.
You can reach me by phone or email:


+972 52-548-6969

, @ Q c

Posts: 5,972 | Comments: 44,523

filter by tags archive

Calculating most popular posts with SubText

How do you get the most popular posts? There are three criteria that you want to check:

  • Aggregator Views
  • Web Views
  • Comments

I decided to give each the following ranking:

  • Each aggregator view counts as 10 points - a lot of people are subscribe to the feed and so they are more likely to go through all the posts
  • Each web view counts counts as 15 points - somebody bothered to go to the site, or arrive via search / link.
  • Each comment gets 35 points - somebody took the time to comment on what I said

This means that a post doesn't get too wieghted toward too much comments (which can happen if a discussion is started) but not enough views.







        ( WebCount * 15 ) + ( AggCount * 10 ) + ( CommentsPerPost * 35 ) weightedScore

FROM    subtext_EntryViewCount,

        ( SELECT    COUNT(dbo.subtext_Feedback.Id) CommentsPerPost,


          FROM      dbo.subtext_Feedback

                    RIGHT JOIN dbo.subtext_Content ON dbo.subtext_Content.Id = dbo.subtext_Feedback.EntryId

          WHERE     FeedbackType = 1

          GROUP BY  dbo.subtext_Content.Id

        ) Comments,


WHERE   Comments.Id = EntryId

        AND Subtext_Content.Id = EntryId

ORDER BY ( WebCount * 15 ) + ( AggCount * 10 ) + ( CommentsPerPost * 35 ) DESC


Ayende Rahien

Sorry, that counts only those that have at least one comment.


This is great ! I was looking to do something like this, just like Community Server has "Most Popular" sections...

Do you think it could be made even more configurable, by passing the points for each type from web.config or somewhere, so that individual bloggers can configure their "most popular" post without recompiling the SP ?


Ayende Rahien

You could pass parameters for the different types, so that wouldn't be a problem

Steve Harman

sniff, sniff

I think I smell a the start of a really cool Plug-in for Subtext v2.0!

This query, and some of the ones from your previous "Blog Stats: SQL" post would be a solid basis around with to build a plugin/skin control for showing off some of the less obvious (but very interesting) stats that your blog has to offer.

verns blog

My 15 Most Popular Posts, via Steve, via Ayende

Community Blogs

Technorati recently released their latest State of The Blogosphere report (renamed to something about

Eduardo Miranda

I just migrated to SubText yesterday and a I used your query to learn a little bit about the SubText database.

Because my blog is not as popular as yours, I found a small "bug" (maybe designed that way) in the query. Posts that don't have comments (as I said, I'm not that popular) doesn't show in the results.

I did a small change in the query to fix it:

WHERE FeedbackType = 1 OR FeedbackType IS NULL

Now it's working for me

Comment preview

Comments have been closed on this topic.


No future posts left, oh my!


  1. Production postmortem (5):
    29 Jul 2015 - The evil licensing code
  2. Career planning (6):
    24 Jul 2015 - The immortal choices aren't
  3. API Design (7):
    20 Jul 2015 - We’ll let the users sort it out
  4. What is new in RavenDB 3.5 (3):
    15 Jul 2015 - Exploring data in the dark
  5. The RavenDB Comic Strip (3):
    28 May 2015 - Part III – High availability & sleeping soundly
View all series


Main feed Feed Stats
Comments feed   Comments Feed Stats