php mysql FULLTEXT 搜索多个单词

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6717312/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 01:03:45  来源:igfitidea点击:

mysql FULLTEXT search multiple words

phpmysqlsearch

提问by iamwhitebox

I've never really heard a straight answer on this one, I just need to FULLTEXT search a couple columns with multiple words "Firstname Lastname"

我从来没有真正听到过关于这个问题的直接答案,我只需要全文搜索几个包含多个单词“名字姓氏”的列

$sql = mysql_query("SELECT * FROM 
                    patient_db 
                    WHERE MATCH ( Name, id_number )
                    AGAINST ('% $term %' IN BOOLEAN MODE);");

But it fails to run the query if I enter more than one word here.

但是,如果我在此处输入多个单词,则无法运行查询。

回答by Vineet1982

$sql = mysql_query("SELECT * FROM 
         patient_db WHERE 
         MATCH ( Name, id_number ) 
         AGAINST ('+first_word +second_word +third_word' IN BOOLEAN MODE);");

and if you want to do exact search:

如果您想进行精确搜索:

$sql = mysql_query("SELECT * 
                  FROM patient_db 
                  WHERE MATCH ( Name, id_number ) 
                  AGAINST ('"exact phrase"' IN BOOLEAN MODE);");

回答by Jacob

SELECT * 
FROM patient_db 
WHERE MATCH ( Name, id_number ) 
      AGAINST ("Firstname Lastname" IN BOOLEAN MODE);

The double-quotes are important. This looks for literally the phrase "Firstname Lastname". You don't need the percentage signs.

双引号很重要。这从字面上查找短语“Firstname Lastname”。您不需要百分比符号。

If you look for "Firstname blahblahblah Lastname blahblah", the AGAINST()clause has to look like this:

如果您查找“Firstname blahblahblah Lastname blahblah”,则该AGAINST()子句必须如下所示:

AGAINST ('+Firstname +Lastname' IN BOOLEAN MODE);

Have look at the MySQL docs on full text searchfor more info.

查看有关全文搜索MySQL 文档以获取更多信息。

Another thing: why do you have the id_numbercolumn in your match?

另一件事:为什么id_number你的比赛中有专栏?