kar*_*ila 0 mysql search full-text-search
我有一张桌子,我正在插入例如图像和所述图像中找到的颜色的名称.颜色字符串看起来像"白色,黄色,橙色,黑色".
由于我有很多这些,50%的阈值开始下降一些颜色,因为它们出现在大多数行上.
表的重点是能够按颜色搜索.有没有人有解决方法,或者我应该放弃并购买Sphinx或类似的东西?重新编译MySQL可能不是一个选择.
我听说有些人只是在表中添加虚拟行以绕过50%,但这听起来非常绝望.
这不是用全文搜索解决的问题.
相反,您需要一个子表,每个图像每种颜色一行.
颜色应该是颜色表的外键,因此您的子表实际上变成了图像和颜色之间的多对多关系.
create table color (
id int not null primary key auto_increment,
name varchar64)
);
create table image_color (
image_id int references image(id),
color_id int reference color(id),
unique constraint (image_id, color_id)
) ;
Run Code Online (Sandbox Code Playgroud)
然后索引关系(并在元组上给它一个唯一约束(image_id,color_id).
然后找到具有特定颜色的所有图像:
select a.* from image a
join image_color b on (a.id = b.image_id)
join color c on (b.color_id = c.id)
where c.name = 'yellow';
Run Code Online (Sandbox Code Playgroud)