Rank SQL full text query by relevance in boolean mode

  • 3/31/2011

Assuming that $keywords holds the query keywords, a table containing the indexed columns title and body may be queried for relevant results using:

SELECT mytable.*, MATCH(title,body) 
AGAINST('$keywords') AS relevance 
FROM `mytable` 
WHERE MATCH(title,body) AGAINST('$keywords' IN BOOLEAN MODE) 
ORDER BY relevance DESC

Hey, it's RJ—thanks for reading! If you enjoyed this post, would you be willing to share it on Twitter, Facebook, or LinkedIn?