MySQL - Most relevant weighted results based (MATCH AGAINST)


/ Published in: MySQL
Save to your folder(s)



Copy this code and paste it in your HTML
  1. SELECT *, (
  2. (1.2 * (MATCH(title) AGAINST (`".$keyword."` IN BOOLEAN MODE))) +
  3. (0.8 * (MATCH(description) AGAINST (`+".$keyword."` IN BOOLEAN MODE))) +
  4. (1.0 * (MATCH(tags) AGAINST (`".$keyword."` IN BOOLEAN MODE)))
  5. ) AS relevance
  6. FROM `".$table_posts."`
  7. MATCH (title, description, tags) AGAINST ('".$keyword."' IN BOOLEAN MODE)
  8. ORDER BY relevance DESC
  9. LIMIT 0,5

URL: http://xaviesteve.com/category/web-design/mysql/

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.