create table test(  
id int auto_increment primary key,  
title VARCHAR(200),  
body TEXT,  
FULLTEXT (title,body)  
);insert into test values(56, 'the line', '爱我');
insert into test values(57, 'the line', '爱我别走');
insert into test values(33, 'the line', '中国');
insert into test values(58, 'the line', '美国');select id, title, body from test where match(title, body) against('爱我');
select id, title, body from test where match(title, body) against('爱我别走');
select id, title, body from test where match(title, body) against('中国');
select id, title, body from test where match(title, body) against('美国');如果说按照上边的查询语句去查找这些中文,'爱我','爱我别走'这类词没有找到的话,我觉得很正常,因为mysql数据库里没装什么中文分词插件,
可是没想到'中国','美国'这些词却能够检索到,难道mysql内有一个中文分词的词库?如果有的话,在什么地方?我该如何使用?我的数据库版本是5.1.35-community

解决方案 »

  1.   

    用空格认为分开的记录也能被检索到:insert into test values(77, 'the line', '中国 美国');
    但这个是肯定检索不到的:insert into test values(88, 'the line', '爱我 别走');   
      

  2.   

    没办法,FULLTEXT 是基于词的
      

  3.   

    确实奇怪,测试了那么多词,只有中国和美国这两个词被分出来了,估计是这两个词的内码正好跟什么英文单词相符?
    mysql> select id, title, body from test where match(title, body) against('中国');
    +----+----------+-----------+
    | id | title    | body      |
    +----+----------+-----------+
    | 32 |          | 中国      | 
    | 77 | the line | 中国 美国 | 
    +----+----------+-----------+