MySQL MATCH 不能使用两个字符?
我有一个名为“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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
更新
my.cnf
MySQL 配置文件中的ft_min_word_len
变量:请注意,之后必须重建索引。
Update the
ft_min_word_len
variable in themy.cnf
MySQL configuration file:Note that afterwards indexes must be rebuilt.
全文搜索会停止一些常见单词,但使用此步骤将禁用它。
1:打开MYSQL配置文件中的my.ini文件。
2:将 ft_min_word_len=1 行放在 my.ini 中的 [mysqld] 行之后
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
3: restart your server
4: repair your table using below command
5: now your search is working....
看起来您遇到了最小长度限制,如 MySQL 文档。
Looks like you're running into the minimum length limit, as stated in the MySQL docs.
供将来参考。上面的答案与
myisam
引擎有关(而不是innodb
)。因此,要修复 innodb 的最小单词长度,您需要 innodb_ft_min_token_size (默认值:3)
my.cnf
:然后重建索引(source):
为了检查您使用的引擎,请执行以下查询并查看
Engine
列:For future references. The answers above are related to
myisam
engine (notinnodb
).So, to fix the minimum length of words for
innodb
you need innodb_ft_min_token_size (default value: 3)my.cnf
:Then rebuild the index (source):
In order to check which engine you use execute the following query and see the
Engine
column:我测试了MyISAM 和InnoDB。
前导“*”似乎被忽略了。
由于尾随“*”,
ft_min_word_len
或innodb_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
orinnodb_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".