沃梦达 / 编程问答 / php问题 / 正文

mysql FULLTEXT 搜索多个单词

mysql FULLTEXT search multiple words(mysql FULLTEXT 搜索多个单词)

本文介绍了mysql FULLTEXT 搜索多个单词的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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.

推荐答案

$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);");

这篇关于mysql FULLTEXT 搜索多个单词的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:mysql FULLTEXT 搜索多个单词

基础教程推荐