Ayende @ Rahien

Refunds available at head office

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.

SELECT TOP 15

        EntryId,

        Title,

        WebCount,

        AggCount,

        CommentsPerPost,

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

FROM    subtext_EntryViewCount,

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

                    dbo.subtext_Content.Id

          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,

        Subtext_Content

WHERE   Comments.Id = EntryId

        AND Subtext_Content.Id = EntryId

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

Comments

Ayende Rahien
03/09/2007 08:48 PM by
Ayende Rahien

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

Shiva
03/10/2007 06:49 PM by
Shiva

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 ?

-Shiva

Ayende Rahien
03/10/2007 07:49 PM by
Ayende Rahien

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

Steve Harman
03/13/2007 01:57 AM by
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
03/13/2007 10:53 PM by
verns blog

My 15 Most Popular Posts, via Steve, via Ayende

Community Blogs
04/07/2007 12:50 AM by
Community Blogs

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

Eduardo Miranda
05/07/2007 12:48 PM by
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

Comments have been closed on this topic.