MySQL MATCH 不能使用两个字符?

发布于 2024-09-12 00:10:22 字数 864 浏览 7 评论 0原文

我有一个名为“business”的表,其中包含以下示例数据:

Street - 150 N Michigan Ave.
City - Chicago
State - IL
Zip - 60601

当我运行类似这样的查询时,

SELECT business.* 
    WHERE MATCH(business.Street, business.City, business.State, business.Zip)
                AGAINST('*150*' IN BOOLEAN MODE)
-- IT WORKS


SELECT business.* 
    WHERE MATCH(business.Street, business.City, business.State, business.Zip)
                AGAINST('*Chicago*' IN BOOLEAN MODE)
-- IT WORKS


SELECT business.* 
    WHERE MATCH(business.Street, business.City, business.State, business.Zip)
                AGAINST('*60601*' IN BOOLEAN MODE)
-- IT WORKS


SELECT business.* 
    WHERE MATCH(business.Street, business.City, business.State, business.Zip)
                AGAINST('*IL*' IN BOOLEAN MODE)
-- DOESNT WORK!!

最后一个查询出了什么问题?

有什么想法吗?

I have a table called 'business' with the following sample data:

Street - 150 N Michigan Ave.
City - Chicago
State - IL
Zip - 60601

When I run a query like

SELECT business.* 
    WHERE MATCH(business.Street, business.City, business.State, business.Zip)
                AGAINST('*150*' IN BOOLEAN MODE)
-- IT WORKS


SELECT business.* 
    WHERE MATCH(business.Street, business.City, business.State, business.Zip)
                AGAINST('*Chicago*' IN BOOLEAN MODE)
-- IT WORKS


SELECT business.* 
    WHERE MATCH(business.Street, business.City, business.State, business.Zip)
                AGAINST('*60601*' IN BOOLEAN MODE)
-- IT WORKS


SELECT business.* 
    WHERE MATCH(business.Street, business.City, business.State, business.Zip)
                AGAINST('*IL*' IN BOOLEAN MODE)
-- DOESNT WORK!!

So what's wrong with the last query?

Any ideas?

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

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

发布评论

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

评论(5

爱情眠于流年 2024-09-19 00:10:22

更新 my.cnf MySQL 配置文件中的 ft_min_word_len 变量:

[mysqld]
ft_min_word_len=N

请注意,之后必须重建索引。

Update the ft_min_word_len variable in the my.cnf MySQL configuration file:

[mysqld]
ft_min_word_len=N

Note that afterwards indexes must be rebuilt.

暖心男生 2024-09-19 00:10:22

全文搜索会停止一些常见单词,但使用此步骤将禁用它。

1:打开MYSQL配置文件中的my.ini文件。

2:将 ft_min_word_len=1 行放在 my.ini 中的 [mysqld] 行之后

[mysqld]
ft_min_word_len=1

3:重新启动服务器

4:使用以下命令修复表

修复表表名;

5:现在您的搜索正在运行......

Fulltext search stop some common word, but it is disable using this steps.

1: open my.ini file in MYSQL configuration file.

2: place ft_min_word_len=1 line after [mysqld] line in my.ini

[mysqld]
ft_min_word_len=1

3: restart your server

4: repair your table using below command

repair table tablename;

5: now your search is working....

够钟 2024-09-19 00:10:22

看起来您遇到了最小长度限制,如 MySQL 文档

Looks like you're running into the minimum length limit, as stated in the MySQL docs.

就此别过 2024-09-19 00:10:22

供将来参考。上面的答案与myisam引擎有关(而不是innodb)。

因此,要修复 innodb 的最小单词长度,您需要 innodb_ft_min_token_size (默认值:3)

my.cnf

[mysqld]
innodb_ft_min_token_size=2

然后重建索引(source):

alter table your_name drop index index_name;
alter table your_name add fulltext(field_name);

为了检查您使用的引擎,请执行以下查询并查看 Engine 列:

show table status where `name` = 'table_name';

For future references. The answers above are related to myisam engine (not innodb).

So, to fix the minimum length of words for innodb you need innodb_ft_min_token_size (default value: 3)

my.cnf:

[mysqld]
innodb_ft_min_token_size=2

Then rebuild the index (source):

alter table your_name drop index index_name;
alter table your_name add fulltext(field_name);

In order to check which engine you use execute the following query and see the Engine column:

show table status where `name` = 'table_name';
∞梦里开花 2024-09-19 00:10:22

我测试了MyISAM 和InnoDB。

前导“*”似乎被忽略了。

由于尾随“*”,ft_min_word_leninnodb_min_token_size 被忽略。

如果您的数据集主要针对“IL”中的企业,则可能会出现以下规则:“如果超过 50% 的行包含某个单词,则不会对该单词建立索引。”

另外,不要忘记“停用词”。

I tested both MyISAM and InnoDB.

The leading '*' seems to be ignored.

Because of the trailing '*', ft_min_word_len or innodb_min_token_size is ignored.

If your dataset is mostly for businesses in "IL", the following rule may kick in: "If more than 50% of the rows contain a word, that word is not indexed."

Also, don't forget about "stopwords".

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