mysql关键字搜索

编程入门 行业动态 更新时间:2024-10-28 10:32:22
本文介绍了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.

推荐答案

使用以布尔模式运行的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关键字搜索

本文发布于:2023-11-24 15:24:46,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1625770.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:关键字搜索   mysql

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!