mysql全文搜索fulltext
发布时间:2022-03-30 12:29 所属栏目:115 来源:互联网
导读:mysql select * from t2; +------+------+----------------------------+ | a | b | c | +------+------+----------------------------+ | 1 | aa | aa11111111111111111111111 | | 2 | bb | bb222222222222222222222222 | +------+------+-----------------
mysql> select * from t2; +------+------+----------------------------+ | 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,搜索单词的最小长度和最大长度。 (编辑:ASP站长网) |
相关内容
网友评论
推荐文章
热点阅读