简体   繁体   English

mysql FULLTEXT 搜索多个单词

[英]mysql FULLTEXT search multiple words

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"我从来没有真正听到过关于这个的直接答案,我只需要 FULLTEXT 搜索带有多个单词“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.但如果我在此处输入多个单词,它将无法运行查询。

$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);");
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".这从字面上查找短语“Firstname Lastname”。 You don't need the percentage signs.您不需要百分号。

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 search for more info.查看全文搜索中的 MySQL 文档以获取更多信息。

Another thing: why do you have the id_number column in your match?另一件事:为什么你的比赛中有id_number列?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM