+------+------+----------------------------+
| a | b | c |
+------+------+----------------------------+
| 1 | aa | aa11111111111111111111111 |
| 2 | bb | bb222222222222222222222222 |
+------+------+----------------------------+
2 rows in set (0.00 sec)
MysqL>
--此处测试字符少于4个并且数据只有2行,搜索不到任何记录
MysqL> select match(c) against('bb') from t2;
+------------------------+
| match(c) against('bb') |
+------------------------+
| 0 |
| 0 |
+------------------------+
2 rows in set (0.00 sec)
MysqL> insert into t2 values(3,'bb cc','cc33333333333333333');
Query OK, 1 row affected (0.00 sec)
MysqL> commit;
Query OK, 0 rows affected (0.00 sec)
MysqL> select match(b) against('bb') from t2;
+------------------------+
| match(b) against('bb') |
+------------------------+
| 0 |
| 0 |
| 0 |
+------------------------+
3 rows in set (0.00 sec)
MysqL>
MysqL>
MysqL>
MysqL> insert into t2 values(4,'dd','dd33333333333333333');
Query OK, 1 row affected (0.00 sec)
MysqL> insert into t2 values(5,'ee','ee33333333333333333');
Query OK, 1 row affected (0.00 sec)
MysqL> insert into t2 values(6,'ff','ff33333333333333333');
Query OK, 1 row affected (0.00 sec)
MysqL> insert into t2 values(7,'g','gg33333333333333333');
Query OK, 1 row affected (0.00 sec)
MysqL> insert into t2 values(8,'h','hh43333333333333333');
Query OK, 1 row affected (0.00 sec)
MysqL> insert into t2 values(9,'ii','ii33333333333333333');
Query OK, 1 row affected (0.00 sec)
MysqL> insert into t2 values(10,'jj','jj33333333333333333');
Query OK, 1 row affected (0.00 sec)
MysqL>
MysqL>
MysqL> commit;
Query OK, 0 rows affected (0.00 sec)
MysqL> select match(b) against('bb') from t2;
+------------------------+
| match(b) against('bb') |
+------------------------+
| 0 |
| 0 |
| 0 |
| 0 |
| 0 |
| 0 |
| 0 |
| 0 |
| 0 |
| 0 |
+------------------------+
10 rows in set (0.00 sec)
--大于4个字符可以搜索出来
MysqL> insert into t2 values(10,'kkkkkwq','kkkkk adfsdf');
Query OK, 1 row affected (0.00 sec)
MysqL> select match(c) against('kkkkk') from t2;
+---------------------------+
| match(c) against('kkkkk') |
+---------------------------+
| 0 |
| 0 |
| 0 |
| 0 |
| 0 |
| 0 |
| 0 |
| 0 |
| 0 |
| 0 |
| 2.2508163452148438 |
+---------------------------+
11 rows in set (0.00 sec)
MysqL> select * from t2 where match(c) against('kkkkk');
+------+---------+--------------+
| a | b | c |
+------+---------+--------------+
| 10 | kkkkkwq | kkkkk adfsdf |
+------+---------+--------------+
1 row in set (0.00 sec)
MysqL> select * from t2 where match(b) against('kkkkk');
Empty set (0.01 sec)
MysqL> update t2 set b='kkkkk' where a=10;
Query OK, 2 rows affected (0.00 sec)
Rows matched: 2 Changed: 2 Warnings: 0
MysqL> select * from t2 where match(b) against('kkkkk');
+------+-------+---------------------+
| a | b | c |
+------+-------+---------------------+
| 10 | kkkkk | jj33333333333333333 |
| 10 | kkkkk | kkkkk adfsdf |
+------+-------+---------------------+
2 rows in set (0.00 sec)
--默认自然语言,搜索结果按相关度排序,此处查询结果为相关度
MysqL> select b,match(b) against('kkkkk') from t2;
+-------+---------------------------+
| b | match(b) against('kkkkk') |
+-------+---------------------------+
| aa | 0 |
| bb | 0 |
| bb cc | 0 |
| dd | 0 |
| ee | 0 |
| ff | 0 |
| g | 0 |
| h | 0 |
| ii | 0 |
| kkkkk | 1.486977219581604 |
| kkkkk | 1.486977219581604 |
+-------+---------------------------+
11 rows in set (0.00 sec)
MysqL> select * from t2 where match(b) against('kkkkk');
+------+-------+---------------------+
| a | b | c |
+------+-------+---------------------+
| 10 | kkkkk | jj33333333333333333 |
| 10 | kkkkk | kkkkk adfsdf |
+------+-------+---------------------+
2 rows in set (0.00 sec)
--自然语言搜索
MysqL> select * from t2 where match(b) against('kkkkk' in natural language mode);
+------+-------+---------------------+
| a | b | c |
+------+-------+---------------------+
| 10 | kkkkk | jj33333333333333333 |
| 10 | kkkkk | kkkkk adfsdf |
+------+-------+---------------------+
2 rows in set (0.00 sec)
--布尔型搜索
MysqL> select * from t2 where match(b) against('kkkkk' in boolean mode);
+------+-------+---------------------+
| a | b | c |
+------+-------+---------------------+
| 10 | kkkkk | jj33333333333333333 |
| 10 | kkkkk | kkkkk adfsdf |
+------+-------+---------------------+
2 rows in set (0.01 sec)
--布尔型只包括1和0
MysqL> select b,match(b) against('kkkkk' in boolean mode) from t2;
+-------+-------------------------------------------+
| b | match(b) against('kkkkk' in boolean mode) |
+-------+-------------------------------------------+
| aa | 0 |
| bb | 0 |
| bb cc | 0 |
| dd | 0 |
| ee | 0 |
| ff | 0 |
| g | 0 |
| h | 0 |
| ii | 0 |
| kkkkk | 1 |
| kkkkk | 1 |
+-------+-------------------------------------------+
11 rows in set (0.00 sec)
MysqL>
--多列搜索同一单词为 match(col1,col2) against('word'),
--一列搜索多个单词,match(col) against('word1 word2')
--布尔型搜索与自然语言搜索区别:1,自然按相关度排序,布尔不是,2,对于布尔型搜索,50%规则不起作用
--布尔型两个功能,against里(即搜索的单词)可有+ -号,+表示有。-表示没有,比如 +word1 -word2表示有单词word1但没有word2
--全文搜索参数,ft_min_word_len和ft_max_word_len,搜索单词的最小长度和最大长度
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。