mysql全文搜索失败

时间:2015-06-05 23:05:11

标签: mysql full-text-search

这是我测试过的。

`yourButton.contentEdgeInsets = UIEdgeInsetsMake(0.f, 10.f, 0.f, 10.f);`

这是创建声明。

mysql> select * from product;
+------------+---------+---------------+
| Id         | Product | ProductIdType |
+------------+---------+---------------+
| B00005N5PF | one pen | ASIN          |
| B000J5XS3C |         | ASIN          |
+------------+---------+---------------+
2 rows in set (0.00 sec)

mysql> select * from product p where match (p.Product) against ('pen' in boolean mode);
Empty set (0.00 sec)

mysql> select * from product p where match (p.Product) against ('one pen' in boolean mode);
Empty set (0.00 sec)

等号和'LIKE'工作正常。那么为什么?

1 个答案:

答案 0 :(得分:3)

-- drop table testproduct;
CREATE TABLE testproduct
(
    Id                VARCHAR(16),
    prod_name           TEXT,
    ProductIdType     VARCHAR(8),
  PRIMARY KEY (Id),
  FULLTEXT (prod_name)
) ENGINE=MyISAM;

insert into testproduct (id,prod_name,productidtype) values ('B00005N5PF','one pen and a good price for a pen','ASIN');
insert into testproduct (id,prod_name,productidtype) values ('B570J5XS3C',null,'ASIN');
insert into testproduct (id,prod_name,productidtype) values ('C00ZZ5N5PF','let us get rid of some noise','ASIN');
insert into testproduct (id,prod_name,productidtype) values ('D00LL5N5PA','four score and seven years ago our fore...','ASIN');
insert into testproduct (id,prod_name,productidtype) values ('EEEZZ5N5PF','he has a harpoon','ASIN');
insert into testproduct (id,prod_name,productidtype) values ('C01ZZ5N5PF','and then we','ASIN');
insert into testproduct (id,prod_name,productidtype) values ('B00ZZ5N5PF','he has a pen in his pocket not a banana','ASIN');
insert into testproduct (id,prod_name,productidtype) values ('C02ZZ5N5PF','went to the store','ASIN');
insert into testproduct (id,prod_name,productidtype) values ('C03ZZ5N5PF','and decided that we should buy some','ASIN');
insert into testproduct (id,prod_name,productidtype) values ('C04ZZ5N5PF','fruit cups or fruit or berries or pebbles','ASIN');
insert into testproduct (id,prod_name,productidtype) values ('C037Z5N5PF','then he and her she and it','ASIN');
insert into testproduct (id,prod_name,productidtype) values ('C04K95N5PF','threw some daggers and a harpoon','ASIN');
insert into testproduct (id,prod_name,productidtype) values ('D88895N5PF','more noise and some of this','ASIN');
insert into testproduct (id,prod_name,productidtype) values ('D34595N5PF','this article about harpoons really drills into the throwing of harpoon or harpoons to those that deserve a harpoon','ASIN');
insert into testproduct (id,prod_name,productidtype) values ('D12395N5PF','and there we go','ASIN');

全文搜索需要多种多样才能摆脱重复的“噪音”。使用最少的数据进行测试会产生不良结果把你的整个系列扔到它上面,以获得有意义的东西。如下面的某些链接所示,甚至尝试搜索最小字数的设置。

停止词语

在各种语言中都有MySql Lists of Stop Words表示在搜索过程中跳过的无效字词。该列表被编译到服务器中,但可以覆盖,如Manual Page和text:

中所示
  

要覆盖默认的禁用词列表,请设置ft_stopword_file系统   变量。 (请参见第5.1.4节“服务器系统变量”。)变量   value应该是包含禁用词的文件的路径名   列表,或禁用禁用词过滤的空字符串。服务器   除非是绝对路径名,否则在数据目录中查找该文件   用于指定不同的目录。改变后的价值   这个变量或停用词文件的内容,重启服务器   并重建你的FULLTEXT索引。

一些示例查询

-- select * from testproduct
SELECT * FROM testproduct WHERE MATCH(prod_name) AGAINST('score' IN BOOLEAN MODE);
SELECT * FROM testproduct WHERE MATCH(prod_name) AGAINST('harpoon' IN BOOLEAN MODE);
SELECT * FROM testproduct WHERE MATCH(prod_name) AGAINST('banana' IN BOOLEAN MODE);
SELECT * FROM testproduct WHERE MATCH(prod_name) AGAINST('years' IN BOOLEAN MODE);

获得多个单词匹配:

SELECT id,prod_name, match( prod_name )
AGAINST ( '+harpoon +article' IN BOOLEAN MODE ) AS relevance
FROM testproduct 
ORDER BY relevance DESC

relevance列中给出了真正的分量:

SELECT id,prod_name, match( prod_name )
AGAINST ( '+harpoon +article' IN NATURAL LANGUAGE MODE) AS relevance
FROM testproduct 
ORDER BY relevance DESC
+------------+--------------------------------------------------------------------------------------------------------------------+--------------------+
| id         | prod_name                                                                                                          | relevance          |
+------------+--------------------------------------------------------------------------------------------------------------------+--------------------+
| D34595N5PF | this article about harpoons really drills into the throwing of harpoon or harpoons to those that deserve a harpoon | 3.6207125186920166 |
| EEEZZ5N5PF | he has a harpoon                                                                                                   | 1.2845110893249512 |
| C04K95N5PF | threw some daggers and a harpoon                                                                                   | 1.2559525966644287 |
|------------+--------------------------------------------------------------------------------------------------------------------+--------------------+

解除了here中的多个单词部分。谢谢斯宾塞