WEB开发网
开发学院数据库MySQL 如何在MySQL中获得更好的全文搜索结果 阅读

如何在MySQL中获得更好的全文搜索结果

 2007-11-13 11:02:51 来源:WEB开发网   
核心提示: These guys totally rock! Like, awesome, dude!');验证数据的正确录入:mysql> SELECT * FROM reviews;+++| id | data|+++| 1 | Gingerboy has a new single

These guys totally rock! Like, awesome, dude!');

验证数据的正确录入:

mysql> SELECT * FROM reviews;

+----+--------------------------------------------+

| id | data|

+----+--------------------------------------------+

| 1 | Gingerboy has a new single out called ... |

| 2 | Hello all, I really like the new Madon ...|

| 3 | Have you heard the new band Hotter Than...|

+----+--------------------------------------------+

3 rows in set (0.00 sec)

2、定义全文搜索字段

接下来,定义您要作为全文搜索索引的字段

mysql> ALTER TABLE reviews ADD FULLTEXT INDEX (data);

Query OK, 3 rows affected (0.21 sec)

Records: 3 Duplicates: 0 Warnings: 0

使用SHOW INDEXES命令来检查索引已经被添加了:

mysql> SHOW INDEXES FROM reviews;

+---------+---------------+--------+------+------------+---------+

| Table | Column_name | Packed | Null | Index_type | Comment |

----------+---------------+--------+------+------------+---------+

| reviews | id | NULL | | BTREE | |

| reviews | data | NULL | YES | FULLTEXT | |

+---------+---------------+--------+------+------------+---------+

2 rows in set (0.01 sec)

3、运行全文搜索

当您拥有了数据和索引,就可以使用MySQL的全文搜索了,最简单的全文搜索方式是带有MATCH...AGAINST语句的SELECT查询,以下是一个简单的例子,可以来查找含有单词“single”的记录:

Tags:如何 MySQL 获得

编辑录入:爽爽 [复制链接] [打 印]
赞助商链接