Let’s say I have a Blog posts table that has a rating field which indicates the quality of the post. What is the most efficient way to randomly find a post, with a higher chance of returning a highly ranked post?
I will be implementing this in PHP, MySQL, and possibly Lucene.
You could use a “weighted random” ordering, such as:
The +1 is there to allow posts with 0 score to be selected.
Depending on the average score of your post you may have to multiply the score by another constant factor (e.g..0.5*score+1)Depending on the distribution of your scores you may want to transform your score, for instance with
LOG(score)orSQRT(score).