mysql keyword search

前端 未结 2 1504
后悔当初
后悔当初 2020-12-15 01:48

I have a table with names of movies, and I want to be able to search for a movie in that table. But I want to be able to search for part of the title, and still return a res

相关标签:
2条回答
  • 2020-12-15 02:43

    Use a MySQL Full Text Search in boolean mode. If you do this when you search for '007: quantum solace' as it contains at least one matching result in the column it will be displayed, you can then order by relevancy.

    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
    
    0 讨论(0)
  • 2020-12-15 02:44

    Have a look at the full text search capabilities of MySQL. Once you set up a full text index, you can do queries like this one:

    SELECT * 
    FROM movies
    WHERE MATCH(title) AGAINST ('quantum solace' IN BOOLEAN MODE)
    
    0 讨论(0)
提交回复
热议问题