MYSQL 5.7.17全文搜索

时间:2017-03-18 14:03:51

标签: mysql database full-text-search

Alter表之后的表结构

CREATE TABLE `WINNER` (
  `ID` bigint(20) NOT NULL,
  `CREATED_DATE` datetime NOT NULL,
  `DELETED` bit(1) NOT NULL,
  `EMAIL` varchar(255) DEFAULT NULL,
  `FIRST_NAME` varchar(255) NOT NULL,
  `LAST_NAME` varchar(255) NOT NULL,
  `NO_OF_AWARDS` int(11) DEFAULT NULL,
  `PASSWORD` varchar(255) NOT NULL,
  `PHONE` varchar(10) NOT NULL,
  `country_ID` bigint(20) NOT NULL,
  `orgId_ID` bigint(20) NOT NULL,
  PRIMARY KEY (`ID`),
  UNIQUE KEY `UK_kkk28h9hpbjqvfis7hr4njm1t` (`PHONE`),
  KEY `FK8nj02saxptd0qs5mh7ix6q82a` (`country_ID`),
  KEY `FKlosg52h1cxfljriqt9vhf1b5o` (`orgId_ID`),
  FULLTEXT KEY `PAGINATION_SEARCH` (`FIRST_NAME`,`LAST_NAME`,`PHONE`,`EMAIL`),
  CONSTRAINT `FK8nj02saxptd0qs5mh7ix6q82a` FOREIGN KEY (`country_ID`) REFERENCES `COUNTRY` (`ID`),
  CONSTRAINT `FKlosg52h1cxfljriqt9vhf1b5o` FOREIGN KEY (`orgId_ID`) REFERENCES `ORGANISATION` (`ID`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

修改声明

ALTER TABLE `WINNER`
    ADD FULLTEXT INDEX `PAGINATION_SEARCH` (`FIRST_NAME`, `LAST_NAME`, `PHONE`, `EMAIL`);

以下搜索会引发语法错误。

 select * from `WINNER` WHERE MATHCH(`FIRST_NAME`, `LAST_NAME`, `PHONE`, `EMAIL`)
     AGAINST ('aa' IN NATURAL LANGUAGE MODE);

错误

您的SQL语法有错误;查看与MySQL服务器版本对应的手册,以便在第2行的'反对'('a''自然语言模式)'附近使用正确的语法

2 个答案:

答案 0 :(得分:1)

以下查询中存在拼写错误MATCH

select * from `WINNER` WHERE MATCH(`FIRST_NAME`, `LAST_NAME`, `PHONE`, `EMAIL`)
     AGAINST ('aa' IN NATURAL LANGUAGE MODE);

答案 1 :(得分:0)

你的问题只是单词匹配中的拼写错误,正确的查询是:

 select * from `WINNER` WHERE MATCH(`FIRST_NAME`, `LAST_NAME`, `PHONE`, `EMAIL`)
 AGAINST ('aa' IN NATURAL LANGUAGE MODE);