Algorithm To Select Most Popular Places from Database

不羁的心 提交于 2019-12-04 09:15:35

The exact formula for the favorite would need to come from you, we will call it f(x).
For the actual implementation I would add a popularity_score field that I would calculate, as you said from a nightly cron job using f(x) for each row.

Then it is simply a case of doing a "select place name from table order by popularity_score desc".

Ok - Let's give it a stab popularity_score = (FAVORITE * 3 + COMPLETED * 2 + WISHLIST) * RATING * VIEW / AVG_VIEWS_OF_ALL_PROFILES

I don't have an opinion on how to weigh things.

That said, why not just add a popularity column to the location table? All of a sudden, your SQL query is incredibly simple.

The tricky part, of course, is figuring out how and when to update that value. But since you're saving all of the activity data, you can always regenerate the popularity values from the log entries.

That way, you get nice fast queries for "most popular" locations, and if you want to change the way popularity is computed, you can do so at will.

If you're clever, you might be able to devise a simple enough formula so that popularity can be tracked in real time. For instance, if we only cared about average ratings, you can modify the average rating with just three variables: the current average rating, the number of times the object has been rated, and the new rating value.

Of course, things get more complex when you start mixing in how many times the object has been viewed, reviewed, favorited, etc ... but you might find that you can devise a method that's computationally cheap enough that you can update the overall popularity value on just about every action.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!