下面是我运行的命令
create database fu;
create table table_name( name varchar(10));
insert into table_name values('karan');
insert into table_name values('nitin');
insert into table_name values('orip');
insert into table_name values('karan orip');
insert into table_name values('karan nitin');
alter table table_name add fulltext(name); //fulltext
select * from products where match(name) against('karan');
现在,上面的查询返回空集。这是为什么?
还有,是我吗
select * from products where match(name) against('karan' in boolean mode);
上面的语句给了我完美的结果。
最佳答案
您似乎使用了 MyISAM 存储引擎。存在一个限制,即在超过 50% 的所有行中找到的单词将被视为停用词:
您的搜索词“karan”出现在 5 行中的 3 行中,因此超过了这个标记。
MyISAM Limitation
For very small tables, word distribution does not adequately reflect their semantic value, and this model may sometimes produce bizarre results for search indexes on MyISAM tables. For example, although the word “MySQL” is present in every row of the articles table shown earlier, a search for the word in a MyISAM search index produces no results:
[...]
The search result is empty because the word “MySQL” is present in at least 50% of the rows, and so is effectively treated as a stopword. This filtering technique is more suitable for large data sets, where you might not want the result set to return every second row from a 1GB table, than for small data sets where it might cause poor results for popular terms.
如果您使用的是 MySQL 5.6 或更新版本,则可以使用 InnoDB 引擎解决此问题。
The 50% threshold can surprise you when you first try full-text searching to see how it works, and makes InnoDB tables more suited to experimentation with full-text searches.
关于mysql - 全文搜索未给出所需结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25691797/