Mysql keyword search

I have a table with movie names, and I want to be able to search for a movie in this table. But I want to be able to search for a part of the name and still return the result. For example, if there is an entry called “Quantum of Consolation,” then I want to be able to search for “quantum comfort” or even “007: quantum comfort”, and I want to find this entry. Is there any way to do this?

EDIT And how do I sort by match? That is, the row that matches most should be returned first.

+4
source share
2 answers

Use MySQL Full Text Search in boolean mode. If you do this when you search for “007: quantum leak,” since it contains at least one match result in a column, it will be displayed, then you can sort by relevance.

SELECT *, MATCH(title) AGAINST ('quantum solace' IN BOOLEAN MODE) AS rank FROM films WHERE MATCH(title) AGAINST ('quantum solace' IN BOOLEAN MODE) ORDER BY rank DESC 
+5
source

Check out MySQL's full-text search capabilities . After you set up the full text index, you can make queries like this:

 SELECT * FROM movies WHERE MATCH(title) AGAINST ('quantum solace' IN BOOLEAN MODE) 
+1
source

All Articles