2016-10-13 7 views
0

次の表とストアドプロシージャをループ付きの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  banana   0114 
food  beer    null 
food  rice local  0113 
food  rice imported 0113 

:代わりに

section code    cpc 

food  rice local  2111 
food  rice imported 2111 
food  rice local  0113 
food  rice imported 0113 

は、私が結果として得られたテーブルが欲しいです。

+0

なぜ出力でなければならないと思いますか? FTSに多くのデータを投函して機能させる必要があります。あなたはそれを訓練する。ストップワードで何千もの行を考える。 – Drew

+0

@Drew、たとえ小さなデータセットであっても、正しいマッピングを提供する必要があります。これは私が試しているテストケースにすぎないことに注意してください。ループ構造が間違っていますか? –

+0

FTSは、非FTSのように、担当するAbdullahではありません。それは、ファジーなエンジンに渡して最良の選択をしています。マニュアルに明記されている量が付属しています。だから、FTSと非FTSを混同しないでください – Drew

答えて

0

私は上記のマッピングの練習を、私が持っている別のデータベースで行いました。以下の2つのデータベースがあります - 1つは調査データから、もう1つは国連分類システムからです。調査データ(各種支出項目)と国連分類システムのデータを照合しました。

しかし、生データは異なる命名法の生の意味であるため、結果(一致)はそれほど大きくありません。以下の手順でも部分的な単語マッチングは行われません。マンゴー(生データから)はマンゴーにマップされていませんでした。

ブールモードでは、(ブールモードでは 'mango *')に対してmatch(column1、column2 ..)を含めることができ、部分的な単語マッチングが生成されます。同様の方法で、私はアスタリスクを下のコードの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 ; 
関連する問題