当搜索小于 4 个字符的字符串时,MySQL 中的 MATCH AGAINST 不显示记录

发布于 2024-10-24 20:11:46 字数 183 浏览 1 评论 0原文

我在列上使用 FULLTEXT 索引,当我在布尔模式下使用 MATCH....AGAINST 搜索任何长度小于 4 个字符的搜索词时,它不会返回任何记录。当我使用 LIKE 时,它确实返回记录。 可能是什么问题?是否是因为某些 MySQL 限制(例如它不索引长度小于 4 个字符的单词)或某些特定于 FULLTEXT 索引的限制?

谢谢

I am using FULLTEXT index on a column and when I use MATCH....AGAINST in boolean mode for any search term which is less than 4 characters in length then it doesn't return any records. And when I use LIKE then it does return records.
What could be the problem? Is it because of some MySQL limitation like it doesn't index words that are less than 4 chars in length or some limitation specific to FULLTEXT index?

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

旧梦荧光笔 2024-10-31 20:11:46

检查您的 ft_min_word_len 系统变量。这定义了要索引的单词的最小长度。

更新:好的,我用 ft_min_word_len=3 做了一些测试

首先是一个测试表

CREATE  TABLE `test`.`table1` (
  `id` INT NOT NULL AUTO_INCREMENT ,
  `name` TEXT NULL ,
  PRIMARY KEY (`id`) ,
  FULLTEXT INDEX `Name` (`name` ASC) )
ENGINE = MyISAM;

接下来是一些测试数据:

INSERT INTO `test`.`table1` (`id`, `name`) VALUES ('1', 'This has led in it');
INSERT INTO `test`.`table1` (`id`, `name`) VALUES ('2', 'Led is nice');
INSERT INTO `test`.`table1` (`id`, `name`) VALUES ('3', 'Leds are nicer');
INSERT INTO `test`.`table1` (`id`, `name`) VALUES ('4', 'Nothin here');
INSERT INTO `test`.`table1` (`id`, `name`) VALUES ('5', 'some word which does not exists: abcleddef');

运行这个:

SELECT * FROM `test`.`table1` t1 WHERE match(`t1`.`name`) against ('led' in boolean mode)

返回这个:

1   This has led in it
2   Led is nice

运行这个:

SELECT * FROM `test`.`table1` t1 WHERE match(`t1`.`name`) against ('led*' in boolean mode)

返回这个:

1   This has led in it
2   Led is nice
3   Leds are nicer

所以 FT 搜索可以工作正如预期的那样。您尝试查找的单词有可能实际上是类似 leds 的内容,而不是单个单词 led 吗?

Check your ft_min_word_len system variable. That defines the minimum length of words to be indexed.

Update: Ok I did some tests with ft_min_word_len=3

First a test table

CREATE  TABLE `test`.`table1` (
  `id` INT NOT NULL AUTO_INCREMENT ,
  `name` TEXT NULL ,
  PRIMARY KEY (`id`) ,
  FULLTEXT INDEX `Name` (`name` ASC) )
ENGINE = MyISAM;

Next some test data:

INSERT INTO `test`.`table1` (`id`, `name`) VALUES ('1', 'This has led in it');
INSERT INTO `test`.`table1` (`id`, `name`) VALUES ('2', 'Led is nice');
INSERT INTO `test`.`table1` (`id`, `name`) VALUES ('3', 'Leds are nicer');
INSERT INTO `test`.`table1` (`id`, `name`) VALUES ('4', 'Nothin here');
INSERT INTO `test`.`table1` (`id`, `name`) VALUES ('5', 'some word which does not exists: abcleddef');

Running this:

SELECT * FROM `test`.`table1` t1 WHERE match(`t1`.`name`) against ('led' in boolean mode)

Returns this:

1   This has led in it
2   Led is nice

Running this:

SELECT * FROM `test`.`table1` t1 WHERE match(`t1`.`name`) against ('led*' in boolean mode)

Returns this:

1   This has led in it
2   Led is nice
3   Leds are nicer

So FT search works as expected. Any chance the word you are trying to find is actually something like leds and not the single word led?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文