gpt4 book ai didi

Mysql,用于全文搜索的存储过程产生部分正确的结果

转载 作者:行者123 更新时间:2023-11-29 20:12:00 25 4
gpt4 key购买 nike

我使用循环在 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

我正在向您寻求我的错误的建议。

最佳答案

我使用我拥有的不同数据库进行了上述映射练习。以下是两个数据库 - 一个来自调查数据,另一个来自联合国分类系统。我试图将调查数据(关于各种支出项目)与联合国分类系统中的数据进行匹配。

但是,由于原始数据是原始含义,具有不同的命名法,因此结果(匹配)不是很好。即使下面的过程也不会产生部分单词匹配,例如mango(来自原始数据)未映射到芒果。

在 bool 模式中,您可以包含 match(column1, column2..) against('mango*' in boolean mode) ,它将产生部分单词匹配。以类似的方式,我想在下面的代码中的 v_code 列上添加星号,但这行不通。如果有人有其他想法,非常欢迎。

 ALTER TABLE dbo_CPC
ADD FULLTEXT(`CODE`, description);

ALTER TABLE SLE11_MCPC
ADD FULLTEXT(`CODE`, Section, MCPC);

drop procedure if exists SLE11_CPC_Mapping;
delimiter //
create procedure SLE11_CPC_Mapping()
language sql
DETERMINISTIC
sql security definer
begin
declare v_section VARCHAR(10);
declare v_code text;
declare v_mcpc VARCHAR(10);
declare v_finished int;
declare c cursor for select * from SLE11_MCPC;
declare continue handler for not found set v_finished=1;

DELETE from SLE11_MCPC;

open c;
c_loop: loop
fetch c into v_section, v_code, v_mcpc;
if v_finished then
leave c_loop;
end if;

insert into SLE11_MCPC
select v_section, v_code, left(dbo_CPC.`code`,4)
from dbo_CPC where match (dbo_CPC.Description) against (v_code in
boolean MODE)
LIMIT 1;
end loop c_loop;
close c;

end//
delimiter ;

关于Mysql,用于全文搜索的存储过程产生部分正确的结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40031386/

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