【问题标题】:Mysql, stored procedure for full text search producing partially correct resultsMysql,用于全文搜索的存储过程,产生部分正确的结果
【发布时间】: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


【解决方案1】:

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

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

在布尔模式中,您可以包含 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 ;

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-01-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多