`
hideto
  • 浏览: 2652120 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

MySQL的Full-Text Search

阅读更多
MySQL自带有全文搜索功能: http://dev.mysql.com/doc/refman/5.0/en/fulltext-search.html

创建一个全文搜索表:
CREATE TABLE articles (
  id INT UNSIGNED AUTO_INCREMENT NOT NULL PRIMARY KEY,
  title VARCHAR(200),
  body TEXT,
  FULLTEXT (title, body)
) ENGINE=MyISAM;


插入几条数据:
INSERT INTO articles (title,body) VALUES
  ('MySQL Tutorial','DBMS stands for DataBase ...'),
  ('How To Use MySQL Well','After you went through a ...'),
  ('Optimizing MySQL','In this tutorial we will show ...'),
  ('1001 MySQL Tricks','1. Never run mysqld as root. 2. ...'),
  ('MySQL vs. YourSQL','In the following database comparison ...'),
  ('MySQL Security','When configured properly, MySQL ...');


使用全文搜索查询语句:
SELECT * FROM articles WHERE MATCH (title, body) AGAINST ('database');


MySQL Full-Text Search Functions还支持Boolean模式查询和Query Expansion

MySQL Full-Text Search有一些限制:
1,仅支持MyISAM tables
2,支持大部分多字节字符集,对Unicode只支持utf8不支持ucs2
3,对中文和日语支持不好,因为没有word delimiters
4,若支持在一个单独表中使用多字符集,则所有 FULLTEXT索引中的列 必须使用同样的字符集和库。
5,MATCH()列列表必须同该表中一些 FULLTEXT索引定义中的列列表完全符合,除非MATCH()在IN BOOLEAN MODE
6,对AGAINST() 的参数必须是一个常数字符串

MySQL Full-Text Search的配置
全文变量t_min_word_len、 ft_max_word_len指定搜索字的长度
ft_stopword_file可以自定义保留字
分享到:
评论
1 楼 hideto 2007-12-24  
// mysql.ini
[mysqld]
ft_min_word_len=2   // This will set minimum world length of MySQL Full-Text Search to 2
ft_stopword_file=''     // This will disables MySQL Full-Text Search stopword filtering

相关推荐

Global site tag (gtag.js) - Google Analytics