我有一个包含电影名称的表,我希望能够在该表中搜索电影.但是我希望能够搜索部分标题,并且仍然返回结果.例如,如果有一个名为量子的量子"的记录,那么我希望能够搜索量子的量子",甚至是"007:量子的量子",我想找到该记录.有办法吗?
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 result. For example, if there is a record with the name "The quantum of solace", then I want to be able to do a search for "quantum solace", or even "007: quantum solace" and I want to find that record. Is there a way to do this?
编辑 以及如何根据比赛进行排序?也就是说,最匹配的行应首先返回.
EDIT And how do I sort according to the matches? That is, the row that matches the most, should be returned first.
推荐答案使用以布尔模式运行的MySQL全文搜索. 如果您在搜索"007:量子安慰"时执行此操作,因为它将在显示的列中至少包含一个匹配的结果,则可以按相关性排序.
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更多推荐
mysql关键字搜索
发布评论