使用MySQL全文索引
来源:互联网 发布:上海交大网络空间安全 编辑:程序博客网 时间:2024/05/05 19:22
MySQL的全文索引,不复杂,要掌握它,我只需要掌握三点:
1.创建全文索引的语法。
2.查询时的语法
MATCH() AGAINST ()
3.MySQL全文索引的缺陷。
不必花时间去记这些语法,用到时去查看准确的笔记就可以了。
另外,全文索引里的match()against()的具体使用的含义,我并不清楚,这需要在实践中去弄明白。不在研究这个问题了。
参考资料:
MySQL全文检索笔记 http://www.cnblogs.com/feichexia/archive/2012/06/09/2543049.html
我的测试过程。
一、下载sakila数据库
1.下载地址:http://downloads.mysql.com/docs/sakila-db.zip
2.解压后,执行SQL语句
SOURCE yourpath sakila-schema.sql;SOURCE yourpath sakila-data.sql;
二、使用MySQL全文索引
1.自然语言模式
SQL语句
-- 自然语言模式SELECT film_id, title FROM film_textWHERE MATCH(title,description)AGAINST('Frisbee' IN NATURAL LANGUAGE MODE) LIMIT 6;
+---------+-------------------+| film_id | title |+---------+-------------------+| 308 | FERRIS MOTHER || 326 | FLYING HOOK || 585 | MOB DUFFEL || 714 | RANDOM GO || 210 | DARKO DORADO || 112 | CALENDAR GUNFIGHT |+---------+-------------------+6 rows in set (0.02 sec)
我没有从上述结果中看出该结果和Frisbee有什么关系。
再执行SQL语句
-- 自然语言模式SELECT film_id, title,description FROM film_textWHERE MATCH(title,description)AGAINST('Frisbee' IN NATURAL LANGUAGE MODE) LIMIT 2\G
输出信息
*************************** 1. row *************************** film_id: 308 title: FERRIS MOTHERdescription: A Touching Display of a Frisbee And a Frisbee who must Kill a Girlin The Gulf of Mexico*************************** 2. row *************************** film_id: 326 title: FLYING HOOKdescription: A Thrilling Display of a Mad Cow And a Dog who must Challenge a Frisbee in Nigeria2 rows in set (0.00 sec)
从这个输出结果,我发现了搜索词Frisbee和AGAINST中的description的关系:description中含有关键词Frisbee。但是,关键词和title有什么关系?
执行SQL
-- 自然语言模式SELECT film_id, title,description FROM film_textWHERE MATCH(title)AGAINST('Frisbee' IN NATURAL LANGUAGE MODE) LIMIT 2\G
输出信息
ERROR 1191 (HY000): Can't find FULLTEXT index matching the column list
这说明,Match必须包含所有的fulltext index。
执行SQL
-- 自然语言模式SELECT film_id, title,description FROM film_textWHERE MATCH(title,description)AGAINST('FLYING HOOK' IN NATURAL LANGUAGE MODE) LIMIT 5\G
输出结果
*************************** 1. row *************************** film_id: 326 title: FLYING HOOKdescription: A Thrilling Display of a Mad Cow And a Dog who must Challenge a Frisbee in Nigeria*************************** 2. row *************************** film_id: 430 title: HOOK CHARIOTSdescription: A Insightful Story of a Boy And a Dog who must Redeem a Boy in Australia*************************** 3. row *************************** film_id: 540 title: LUCKY FLYINGdescription: A Lacklusture Character Study of a A Shark And a Man who must Finda Forensic Psychologist in A U-Boat3 rows in set (0.00 sec)
执行SQL语句
-- 自然语言模式SELECT film_id, title,description FROM film_textWHERE MATCH(title,description)AGAINST('FLYING' IN NATURAL LANGUAGE MODE) LIMIT 5\G输出结果
*************************** 1. row *************************** film_id: 326 title: FLYING HOOKdescription: A Thrilling Display of a Mad Cow And a Dog who must Challenge a Frisbee in Nigeria*************************** 2. row *************************** film_id: 540 title: LUCKY FLYINGdescription: A Lacklusture Character Study of a A Shark And a Man who must Finda Forensic Psychologist in A U-Boat2 rows in set (0.00 sec)
与上面的输出结果相比,少了film_id为430的数据,因为关键词中没有HOOK。
在执行SQL语句
-- 自然语言模式SELECT film_id, title,description FROM film_textWHERE MATCH(title,description)AGAINST('FLYING And' IN NATURAL LANGUAGE MODE) LIMIT 5\G输出结果
*************************** 1. row *************************** film_id: 326 title: FLYING HOOKdescription: A Thrilling Display of a Mad Cow And a Dog who must Challenge a Frisbee in Nigeria*************************** 2. row *************************** film_id: 540 title: LUCKY FLYINGdescription: A Lacklusture Character Study of a A Shark And a Man who must Finda Forensic Psychologist in A U-Boat2 rows in set (0.00 sec)
二、布尔模式
执行SQL
-- 布尔模式SELECT film_id,title,description FROM film_textWHERE MATCH(title,description)AGAINST ('technical +writer' IN BOOLEAN MODE)LIMIT 5\G
输出结果
*************************** 1. row *************************** film_id: 19 title: AMADEUS HOLYdescription: A Emotional Display of a Pioneer And a Technical Writer who must Battle a Man in A Baloon*************************** 2. row *************************** film_id: 43 title: ATLANTIS CAUSEdescription: A Thrilling Yarn of a Feminist And a Hunter who must Fight a Technical Writer in A Shark Tank*************************** 3. row *************************** film_id: 44 title: ATTACKS HATEdescription: A Fast-Paced Panorama of a Technical Writer And a Mad Scientist who must Find a Feminist in An Abandoned Mine Shaft*************************** 4. row *************************** film_id: 67 title: BERETS AGENTdescription: A Taut Saga of a Crocodile And a Boy who must Overcome a TechnicalWriter in Ancient China*************************** 5. row *************************** film_id: 86 title: BOOGIE AMELIEdescription: A Lacklusture Character Study of a Husband And a Sumo Wrestler whomust Succumb a Technical Writer in The Gulf of Mexico5 rows in set (0.00 sec)
执行SQL
-- 布尔模式SELECT film_id,title,description FROM film_textWHERE MATCH(title,description)AGAINST ('technical -writer' IN BOOLEAN MODE)LIMIT 6\G
输出
无数据
执行SQL
-- 布尔模式SELECT film_id,title,description FROM film_textWHERE MATCH(title,description)AGAINST ('"Fight a Pastry Chef"' IN BOOLEAN MODE)LIMIT 5\G输出
*************************** 1. row *************************** film_id: 11 title: ALAMO VIDEOTAPEdescription: A Boring Epistle of a Butler And a Cat who must Fight a Pastry Chef in A MySQL Convention1 row in set (0.00 sec)
0 0
- 使用MySQL全文索引
- Mysql 使用全文索引
- Mysql表使用全文索引
- 使用MySQL进行全文索引
- 在mysql中使用全文索引
- MySQL使用全文索引(fulltext index)
- MySQL使用全文索引(fulltext index)
- 关于Mysql 全文索引的使用
- MySQL普通索引、唯一索引、主索引、外键索引、复合索引、全文索引的使用
- MySQL全文索引 Fulltext
- mysql中文全文索引
- mysql全文索引中文搜索
- mysql中文全文索引
- 研究 mysql 全文索引
- Mysql全文索引
- mysql开启全文索引
- mysql中文全文索引
- mysql全文索引
- 好不容易大白天
- iOS开发何如在调试的时候轻松找到程序在哪里崩溃
- 那些困扰我的计算机术语
- circumgyrate the string 2137
- android编译环境搭建后ubuntu12.04黑屏不能进系统( libgl1-mesa-glx:i386)
- 使用MySQL全文索引
- Eclipse将引用了第三方jar包的Java项目打包成jar文件的两种方法
- 大数据究竟是什么?
- Linux驱动程序的模块参数
- asp.net获取当前时间
- apache kafka系列之-监控指标
- android CMWAP, CMNET有何区别
- thrift_demo
- 【HTTP协议】HTTP请求、请求头、HTTP响应、状态吗、响应头、使用响应头编程