Skip to main content

MySQL most relevant weighted search results based (MATCH AGAINST).

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;