0

Im working on the search feature for my app and I would like to give users the option for some sorting of viewing the recipes. Im trying to make a popular feature but Im not entirely sure where to start and if I need to make any modifications to my schema. Ive read this post http://sorentwo.com/2013/12/30/let-postgres-do-the-work.html and get the jist of what its doing. My main question is how do I track when a page is viewed and use that in the calculations? And also track views over time?

Also for using things like comments as a weight is it better to count the number of comments dynamically (query the comment table and add them up) or keep a column in the recipe table that gets added to whenever a comment is added?

DRing
  • 6,825
  • 6
  • 29
  • 45
  • if you do go for comments as a weight to have counter_cache to make it more efficient when retrieving the counts of an object. – mrvncaragay Aug 09 '16 at 20:42
  • Ok, sweet thanks for the point towards counter_cache, I was gonna implement that myself didnt realize there was already a feature. Any input on how to handle tracking views – DRing Aug 09 '16 at 21:06
  • look into this page it might give you what you want with tracking views: http://stackoverflow.com/questions/4815713/simple-hit-counter-for-page-views-in-rails – mrvncaragay Aug 09 '16 at 21:14
  • Thanks that will work for what I need, now I just need to work out the equation to take everything into account...but that is just a math problem and doing some reading – DRing Aug 09 '16 at 22:29

0 Answers0