문제

I'm building an application in PHP with MySQL where users can post articles and they also can rate those with a 5-star system. I've been thinking that I should move the high-rated a little bit to the top when the user perform a text search, so better articles will be easily found.

I'm using the MySQL FULL TEXT index to perform the search, so the relevance score come from that search.

I wonder how I could use the star-rating to tamper with the search relevance (without frustrating the user)?

I though in doing simple multiplication to raise the relevance rating times. That would make 5-star articles 5 times more relevant than 1-star, like this:

SELECT *, (MATCH (title, tags, content) AGAINST('search terms')) *
   rating AS score
 FROM articles WHERE MATCH (title, tags, content) AGAINST('search terms')
 ORDER BY score DESC

Is that a good idea?

I also thought in multiplying the relevance by the logarithm of the rating (plus 1, to avoid decreasing relevance when the rating is below e), so the increase is not so high. That would also made bad rated articles having a better chance if the relevance is higher. The statement would be like this:

SELECT *, (MATCH (title, tags, content) AGAINST('search terms')) *
   (1 + LN(rating)) AS score
 FROM articles WHERE MATCH (title, tags, content) AGAINST('search terms')
 ORDER BY score DESC

Which approach I should use? Is there a better method? Or is it better to ignore user ratings and only use term relevance?

(As a side question, what would happen to non-rated articles?)

도움이 되었습니까?

해결책

The 2nd one sounds better. You should definitely take user ratings into account.

What would happen to non-rated articles, They will be at the bottom of the list of course, which is what you want right?

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top