I'm currently in the way of implementing Trending Topics to my Rails application.
What I currently have is this:
Each post has topic
attribute of 2 to 3 words describing its topic.
Then I get the top posts by their view count (I have also likes & favorites available, but for the time being using simply views):
def trending_topics
Post.order("COALESCE(impressions_count, 0) DESC").limit(200)
end
And then what I do is to simply choose only unique topics and display a number of them:
<% trending_topics.select(:topic).map(&:topic).uniq.take(10).each do |topic| %>
<li><%= topic %></li>
<% end %>
My questions are:
- Is there a way to get most frequently appearing
:topic
, rank them, and pick the cream of the crop of those? - Is this a sustainable way to keep track of popular topics? If not, is there a way to make it more efficient?
- Is there a better way to implement a function that searches for the
most popular and frequent
:topic
attributes in posts?