V
V
Vladimir Sokolovsky2011-03-30 13:00:14
Database design
Vladimir Sokolovsky, 2011-03-30 13:00:14

How to organize ratings on the site?

Seemingly simple solution put me in a stupor. The task is to organize the ratings of different parts of the site, such as users, comments, individual pages, videos. Comments and users should have two rating options - plus and minus. The rest of the parts are 5 star rating.

There are three ideas:
1. Create a table with the fields id_of_the_user_who_changed_the rating, the value_which_the_user_entered (+1/-1, or 1,2,3,4,5), the_application_name_in_which_the_rating_changed (news, comments, user) and the unique_id_of_the_application_post.
The entries will look like:
307|-1|'comments'|3425
26|1|'comments'|3425
141|4|'news'|22

2. Almost the same as the first option, but do not record each rating change, but overwrite the final rating result for the application, that is, add a general rating field to each application.
The entries will look like this:
307|'comments'|3425
26|'comments'|3425
141|'news'|22
And in the comments and news application table, the overall rating for each entry will already be calculated.

3. For each application, make a table with ratings (inconvenient when adding new applications).

Answer the question

In order to leave comments, you need to log in

2 answer(s)
Z
ZloiZmei, 2011-03-30
@ZloiZmei

I propose this:
1. The table with each vote is shared - as long as the load allows (in most projects - forever).
2. The rating of each entry is stored in the application table for each entry. Let's say we store the number of votes and the amount there. Either the number and average - as you like, and depending on what they do more often - they look (then the number and average - it is more convenient to sort and display the value) or vote (then the number and amount)
The algorithm is respectively as follows:
- check if the user can vote (IP, cookie, sessions, date of the previous vote, etc.)
- we give / do not give him the opportunity to vote
- we check again if the user is cheating - we can warn
- we record the vote if everything is correct
- update the number and sum\average

W
webzest, 2011-03-30
@webzest

The second option contains a vulnerability: it is impossible to roll back changes (deleted comment, news, entry).

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question