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, I'm RJ! For more learnings about software and management, find me @rjzaworski or sign up for my semi-regular newsletter.

Let’s keep in touch

Send me timely updates on software, product, and process.