Each product a product_date_added
which is a Date
field contained the date it was added.
They also have a product_views
which is an int
field containing how many times a product has been viewed.
To display products by popularity, I us an algorithm to calculate how many hits per day a product has.
SELECT
AVG(product_views / DATEDIFF(NOW(), product_date_added)) as avg_hits
, product_table.*
FROM product_table
WHERE product_available = "yes"
GROUP BY product_id
ORDER BY avg_hits DESC
This works, but the boss is noticing a lot of older products showing up first. So he basically wants newer views to have more weight than older views.
His suggestion was that any views over a year old don't count. I think I would have to keep a date of every view in order to do that, which I think would slow down performance.
What is the best way to create a popularity algorithm like what my boss is asking for?
Ideally I would want to be able to come up with something that doesn't alter the table structure. If that is not possible, I would at least like to come up with a solution that can use the existing data so we are not starting from 0. If thats not possible either than anything that will work.