Most relevant weighted results

Submitted by:David Villa

Date added:07 January, 2013

Category:MySQL

MySQL code for most relevant weighted results based (MATCH AGAINST)

Tags: match function

Code Snippet:

    SELECT *, (
(1.2 * (MATCH(title) AGAINST (`".$keyword."` IN BOOLEAN MODE))) +
(0.8 * (MATCH(description) AGAINST (`+".$keyword."` IN BOOLEAN MODE))) +
(1.0 * (MATCH(tags) AGAINST (`".$keyword."` IN BOOLEAN MODE)))
) AS relevance
FROM `".$table_posts."`
WHERE
MATCH (title, description, tags) AGAINST ('".$keyword."' IN BOOLEAN MODE)
ORDER BY relevance DESC
LIMIT 0,5
 
 

Comments