我对MATCH AGAINST函数有问题。
以下查询给我相同的结果:
SELECT * FROM models MATCH(name) AGAINST('Fiat 500') SELECT * FROM models MATCH(name) AGAINST('Fiat')
如何在“全文”表的列中搜索字符串和数字?
谢谢
如果您需要的地方Fiat和500顺序无关紧要,那么
Fiat
500
SELECT * FROM models MATCH(name) AGAINST('+Fiat +500');
如果你需要Fiat 500在一起,那么
Fiat 500
SELECT * FROM models MATCH(name) AGAINST('+"Fiat 500"');
如果需要,Fiat并且为零或更多500,则
SELECT * FROM models MATCH(name) AGAINST('+Fiat 500');
如果需要,500并且为零或更多Fiat,则
SELECT * FROM models MATCH(name) AGAINST('Fiat +500');
试试看 !!!
这是FULLTEXT搜索的默认设置
mysql> show variables like 'ft%'; +--------------------------+----------------+ | Variable_name | Value | +--------------------------+----------------+ | ft_boolean_syntax | + -><()~*:""&| | | ft_max_word_len | 84 | | ft_min_word_len | 4 | | ft_query_expansion_limit | 20 | | ft_stopword_file | (built-in) | +--------------------------+----------------+ 5 rows in set (0.00 sec) mysql>
请注意,默认情况下 ft_min_word_len 为4。令牌500的长度为3。因此它根本不会被索引。您将必须做三(3)件事:
将此添加到 /etc/my.cnf
/etc/my.cnf
[mysqld] ft_min_word_len = 1
service mysql restart
models
您可以删除并添加FULLTEXT索引
或分阶段进行,看看它会提前多大
CREATE TABLE models_new LIKE models; ALTER TABLE models_new DROP INDEX name; ALTER TABLE models_new ADD FULLTEXT name (name); ALTER TABLE models_new DISABLE KEYS; INSERT INTO models_new SELECT * FROM models; ALTER TABLE models_new ENABLE KEYS; ALTER TABLE models RENAME models_old; ALTER TABLE models_new RENAME models;
当您感到满意时,请运行
DROP TABLE models_old;