mysql关键字搜索 [英] mysql keyword search

查看:82
本文介绍了mysql关键字搜索的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含电影名称的表,我希望能够在该表中搜索电影.但是我希望能够搜索部分标题,并且仍然返回结果.例如,如果有一个名为量子的量子"的记录,那么我希望能够搜索量子的量子",甚至是"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.

推荐答案

使用

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关键字搜索的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆