mysql fulltext搜索_MySQL中的FULLTEXT搜索不会返回任何行

bd96500e110b49cbb3cd949968f18be7.png

I am a bit lost, this looks like some silly mistake - but I have no clue what that can be. Here is the test session:

mysql> drop table articles;

Query OK, 0 rows affected (0.02 sec)

mysql> CREATE TABLE articles (body TEXT, title VARCHAR(250), id INT NOT NULL auto_increment, PRIMARY KEY(id)) ENGINE = MYISAM;

Query OK, 0 rows affected (0.02 sec)

mysql> ALTER TABLE articles ADD FULLTEXT(body, title);

Query OK, 0 rows affected (0.02 sec)

Records: 0 Duplicates: 0 Warnings: 0

mysql> insert into articles(body) values ('Maya');

Query OK, 1 row affected (0.00 sec)

mysql> SELECT * FROM articles WHERE MATCH(title, body) AGAINST('Maya');

Empty set (0.00 sec)

mysql> select * from articles

-> ;

+------+-------+----+

| body | title | id |

+------+-------+----+

| Maya | NULL | 1 |

+------+-------+----+

1 row in set (0.00 sec)

This is on "mysqld Ver 5.1.37-1ubuntu5 for debian-linux-gnu on i486 ((Ubuntu))".

Here is the script for simple cut and paste (please try it and verify if it works on your system):

CREATE TABLE articles (body TEXT, title VARCHAR(250), id INT NOT NULL auto_increment, PRIMARY KEY(id)) ENGINE = MYISAM;

ALTER TABLE articles ADD FULLTEXT(body, title);

insert into articles(body) values ('Maya');

SELECT * FROM articles WHERE MATCH(title, body) AGAINST('Maya');

解决方案

In MySQL there are three types of full-text searches:

boolean search

natural language search (used by default)

query expansion search

A natural language search interprets

the search string as a phrase in

natural human language (a phrase in

free text). There are no special

operators. The stopword list applies.

In addition, words that are present

in 50% or more of the rows are

considered common and do not match.

Full-text searches are natural

language searches if the IN NATURAL

LANGUAGE MODE modifier is given or if

no modifier is given.

For example, try to add two more records:

INSERT INTO articles(body) VALUES ('Some text'), ('Another text');

And run the same SELECT again - it will work.

As a workaround, you can use boolean mode, which doesn't have this "50%" rule:

SELECT * FROM articles WHERE MATCH(title, body) AGAINST('Maya' IN BOOLEAN MODE);

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值