I am trying to search a table for records according to relevance with search keywords.
我正在尝试根据与搜索关键字的相关性在表中搜索记录。
My query is:
我的查询是:
SELECT *
FROM downloads
WHERE (
(name LIKE '%Micky Mobile%')
OR (name LIKE '%Micky%' OR name LIKE '%Mobile%')
OR (name LIKE '%Micky%')
OR (name LIKE '%Mobile%')
) AND app='1'
This works fine but problem is:
这很好但问题是:
What I want from this query is the row that has name "Hello Micky Mobile T" at 1st place.
我想从这个查询中得到的是第一个名称为“Hello Micky Mobile T”的行。
Row having name "Hello Micky T Mobile" at 2nd place.
名为“Hello Micky T Mobile”的排在第2位。
Row having "Hello Micky T" at 3rd place.
排在第3位的“Hello Micky T”。
Row having "Hello Mobile T" at 4th place.
排在第4位的“Hello Mobile T”。
But above query gives results in ASC order by id(Auto incremented field).
但是上面的查询通过id(自动递增字段)按ASC顺序给出结果。
Union solves my problem but it takes much more time that it should (I suppose). There must be an other way.
联盟解决了我的问题,但它应该花费更多的时间(我想)。必须有另一种方式。
1 个解决方案
#1
2
First of all, it looks like you're searching for Micky and Mobile twice.
首先,看起来你正在寻找Micky和Mobile两次。
Secondly, I believe MySQL has some Full-Text Search possibilities that have relevance options built-in to them: MATCH (col1,col2,...) AGAINST (expr [search_modifier])
其次,我相信MySQL有一些全文搜索可能性,内置相关选项:MATCH(col1,col2,...)AGAINST(expr [search_modifier])
#1
2
First of all, it looks like you're searching for Micky and Mobile twice.
首先,看起来你正在寻找Micky和Mobile两次。
Secondly, I believe MySQL has some Full-Text Search possibilities that have relevance options built-in to them: MATCH (col1,col2,...) AGAINST (expr [search_modifier])
其次,我相信MySQL有一些全文搜索可能性,内置相关选项:MATCH(col1,col2,...)AGAINST(expr [search_modifier])