开发者

How to get search results in order of relevance in mysql?

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.

Row having name "Hello Micky T Mobile" at 2nd place.

Row having "Hello Micky T" at 3rd place.

Row having "Hello Mobile T" at 4th place.

But above query gives results in ASC order by id(Auto incremented 开发者_如何转开发field).

Union solves my problem but it takes much more time that it should (I suppose). There must be an other way.


First of all, it looks like you're searching for Micky and Mobile twice.

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])

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜