I'm trying to implement a trending feature. The trending feature is based on searches that have become viral in a span of 4 hours. It will get the 6 latest popular searches.
Of course, to pull that off, I created a model called
Search that has a
keyword field. Every search done on the application will be stored as one row in the
At the moment, this is what I'm doing to retrieve the keywords to be classified as trending:
@popular_search = Search.where('created_at >= ?', 4.hours.ago).group(:keyword).order('count_keyword DESC').limit(6).count(:keyword)