MySQL Related Search (title+tags+description)

What you think? What will be the best option to search related videos in mysql videos table with matching title+tags+description?

Very easy Idea!

# SELECT * FROM `videos` WHERE title LIKE ‘%$title%’ OR tags LIKE ‘%$tags%’ OR description LIKE ‘%$description’;

Full-text Search is a feature introduced to MySQL in version 3.23.23.

You have to add key in videos table for title+tags+description….

# ALTER TABLE `videos` ADD FULLTEXT(`title`,`tags`,`description`);

# SELECT *, MATCH(`title`,`tags`,`description`) AGAINST (“‘.$search_string.'”) as Relevance FROM `videos` WHERE MATCH (`title`,`tags`,`description`) AGAINST(“‘.$search_string.'” IN BOOLEAN MODE) ORDER BY `Relevance` DESC;

# SELECT * FROM `videos` WHERE MATCH (`title`,`tags`,`description`)
AGAINST (‘+myspace -youtube’ IN BOOLEAN MODE);

These SQL will return result automatically sorted by relevancy.

Published by

Sandeep Verma

I’m an Entrepreneur. I’m proud to work as Blogger, LAMP Programmer, Linux Admin, Web Consultant, Cloud Manager, Apps Developer, Searcher. Concentrate > Observe > Imagine > Launch