mysql - 全文搜索未给出所需结果

标签 mysql full-text-search

下面是我运行的命令

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 manual, Natural Language Full-Text Searches

关于mysql - 全文搜索未给出所需结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25691797/

相关文章:

mysql - 用户 'root@localhost' 的访问被拒绝(使用密码 :NO)

php - 'where 子句 PHP/MySQL 问题中的未知列 '...'

php - 在 mysql 创建表的名称中使用 php 变量

android - 成功构建发布APK但无法安装

mysql - 在 MySQL 中对 JSON 字段进行全文搜索

php - 使用案例PDO全文搜索时如何按相关性排序

mysql - 我得到 Cannot add or update a child row : a foreign key constraint fails error

parsing - 出于地理编码目的解释文本输入的最佳方法是什么?

MySQL 全文不准确

mysql - 是否可以在 bool 模式和查询扩展下执行全文索引搜索?