mysql全文搜索fulltext
发表于:2025-01-20 作者:千家信息网编辑
千家信息网最后更新 2025年01月20日,mysql> select * from t2;+------+------+----------------------------+| a | b | c |+------+------+----
千家信息网最后更新 2025年01月20日mysql全文搜索fulltextmysql> 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,搜索单词的最小长度和最大长度
+------+------+----------------------------+
| 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,搜索单词的最小长度和最大长度
搜索
布尔
单词
自然
相关度
自然语言
语言
字符
结果
长度
排序
全文
最大
最小
两个
作用
功能
参数
只有
多个
数据库的安全要保护哪些东西
数据库安全各自的含义是什么
生产安全数据库录入
数据库的安全性及管理
数据库安全策略包含哪些
海淀数据库安全审计系统
建立农村房屋安全信息数据库
易用的数据库客户端支持安全管理
连接数据库失败ssl安全错误
数据库的锁怎样保障安全
服务器能保存qq记录吗
华为服务器哪些系列
东源供应链软件开发
网络安全咨讯
研究生论文数据库
加强公共网络安全
中山非凡网络技术
计算机局域网的硬件组成是服务器
网络安全 赛前准备 新闻
虚拟者网络安全团队官方博客
在哪里找番茄基因组数据库
在职人员参加网络安全知识竞赛
数据库系统概论第五版王珊目录
嵌入式软件开发研究生
jsp轮播数据库图片
文件数据库设计
全国教师网络安全
我的世界手机基岩版服务器卡顿
中国和韩国网络安全技术
数据库工程师技术栈
5G网络技术模式与核心优势
企业需要网络安全准备哪些
gis平台数据库的建立与更新
数据库采用了哪些安全技术
模板网络安全手抄报
江苏常州服务器整体机柜云空间
湖州信息网络技术诚信为本
asam数据库名
汇总12个月的数据库
奉贤区系统软件开发中心