如何更精确地搜索和排序记录 [英] How to search and sort the records more precisely

查看:76
本文介绍了如何更精确地搜索和排序记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在我的站点中创建一个搜索框,以从mysql数据库中搜索电影标题.我在对搜索结果进行排序时遇到问题.
让我告诉你问题所在.
我得到了用户输入的搜索字符串,然后将该字符串拆分为多个单词,并将这些单词存储到一个array(str [])中.现在,我正在使用此查询从数据库中进行搜索.
假设str数组有五个词.

I am trying to make a search box in my site to search the movie titles from the mysql database. I am facing a problem in sorting the search results.
Let me tell you the problem.
I get the search string entered by the user, then I split this string into words and store these words into an array(str[]). Now I am using this query to search from the database.
suppose str array has five words.

query = "select from tbl_name where moviename = str[0] ";
query .= "or moviename = str[1] or moviename = str[2] ";
query .= "or moviename = str[3] or moviename = str[4]";





众所周知,此查询将从数据库中检索所有包含电影单词的电影标题.

我的问题是,我想将那些电影标题保持在顶部,而这些电影标题具有数组(str)的更多关键字.
假设电影标题包含所有(5)个数组(str)的单词,则它应该在顶部.如果电影标题包含数组(str)的(4)个单词,则它应该在第二个数字上,依此类推.
我该怎么做?





As we know this query will retrieve all the movie titles from the database which contains any of the word of the array.

My Problem is, I want to keep those movie titles on the top which has more keywords of the array (str).
Suppose If a movie title contains all (5) the words of the array (str) then It should be on the top. If a movie title contains (4) words of the array (str) it should on the second number and so on.
How can I do that?

推荐答案

这是一个主意.不知道它是否对您有用.

您可以执行指定的ORDER BY.
Here is an idea. Do not know if it works for you.

You can do a specified ORDER BY.
SELECT FROM tbl_name WHERE moviename = str[0] OR moviename = str[1] ORDER BY moviename = str[0], moviename = str[1]


这篇关于如何更精确地搜索和排序记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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