【发布时间】:2016-10-13 21:33:55
【问题描述】:
我在 mysql 中使用循环创建了以下表和存储过程。它似乎部分起作用。
DROP table if EXISTS x;
DROP table if exists y;
DROP TABLE if EXISTS z;
CREATE TABLE x (`code` VARCHAR(10) not null primary key,
description text, fulltext key(description));
INSERT INTO x
VALUES(2111,'rice, husked'),
('0113','rice, paddy'),
('0124','fish, fresh'),
(2225,'beef meat'),
('0114','bananas'),
('0115','mango');
CREATE TABLE y (section text not null, `code` text);
INSERT INTO y
values('food', 'rice local'),
('food', 'rice imported'),
('food', 'beer'),
('food', 'banana');
create table z (section text not null, `code` text, cpc VARCHAR(10)
NULL);
drop procedure if exists fmatch;
delimiter //
create procedure fmatch()
language sql
deterministic
sql security definer
begin
declare v_code VARCHAR(10);
declare v_description text;
declare v_finished int;
declare c cursor for select * from x ;
declare continue handler for not found set v_finished=1;
delete from z;
open c;
c_loop: loop
fetch c into v_code,v_description;
if v_finished then
leave c_loop;
end if;
insert into z
select y.section, y.`code`, v_code
from y where match (y.`code`) against (v_description in boolean mode);
end loop c_loop;
close c;
select * from z;
end//
delimiter ;
call fmatch();
这里产生的结果为:
section code cpc
food rice local 2111
food rice imported 2111
food rice local 0113
food rice imported 0113
相反,我希望结果表为:
section code cpc
food banana 0114
food beer null
food rice local 0113
food rice imported 0113
如果我错了,我正在寻求您的建议。
【问题讨论】:
-
为什么你认为这应该是输出?您需要在 FTS 上投入大量数据才能使其正常工作。你训练它。想想成千上万行的停用词。
-
@Drew,即使对于少量数据,它也应该给出正确的映射。请注意,这只是我正在尝试的测试用例。循环结构有问题吗?
-
FTS 不像非 FTS 那样由 Abdullah 负责。它把它交给一个模糊引擎来做出最好的选择。并附带手册中明确说明的音量。所以不要将 FTS 与非 FTS 混淆
标签: mysql loops stored-procedures full-text-search