gpt4 book ai didi

mysql - 如何在全文索引列中搜索子字符串?

转载 作者:行者123 更新时间:2023-11-29 16:41:07 25 4
gpt4 key购买 nike

我想在我的全文索引列中搜索子字符串。

我的表格结构是:child_table

clustering_key int(10) unsigned NOT NULL AUTO_INCREMENT,    
Parent_id char(36) NOT NULL DEFAULT '',
child_id char(36) NOT NULL DEFAULT '',
data text,
PRIMARY KEY (clustering_key),
UNIQUE KEY child_index (child_id) USING BTREE,
FULLTEXT KEY data_index (data),
CONSTRAINT FK_child_table_parent_table FOREIGN KEY (Parent_id) REFERENCES parent_table (id) ON DELETE CASCADE ON UPDATE CASCADE )
ENGINE=InnoDB AUTO_INCREMENT=100001 DEFAULT CHARSET=utf8;

假设示例数据是:

enter image description here

我观察到的一些案例:

情况 1: 当我在查询中使用此模式时 MATCH (data) AGAINST ('xy*' IN BOOLEAN MODE) 返回1 行

情况 2: 当我在查询中使用此模式时 MATCH (data) AGAINST ('zy*' IN BOOLEAN MODE) 返回2 行

情况 3:当我在查询中使用此模式时MATCH (data) AGAINST ('*y*' IN BOOLEAN MODE)然后没有返回任何行,但我希望它返回两行。

我认为使用 (*) 作为前缀它不起作用。

请帮我找到解决此问题的方法。

提前致谢

最佳答案

这是正确的行为。来自 manual :

The asterisk serves as the truncation (or wildcard) operator. Unlike the other operators, it is appended to the word to be affected. Words match if they begin with the word preceding the * operator.

换句话说,* 只能在单词末尾使用,如前两种情况(xy*zy*)。如果您想在单词的两端使用通配符匹配,则需要使用 LIKERLIKE 例如

WHERE data LIKE '%y%'

关于mysql - 如何在全文索引列中搜索子字符串?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53333095/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com