Thread wortgruppen vergleichen (10 answers)
Opened by Franz at 2007-03-13 00:21

bloonix
 2007-03-15 15:44
#75004 #75004
User since
2005-12-17
1615 Artikel
HausmeisterIn
[Homepage]
user image
Hallo doc,

[quote=docsnyder,15.03.2007, 10:10]Hallöle?

Wenn sich die Daten sowieso in einer DB befinden, kann die Suche auf 2 übereinstimmende Elemente nicht mit DB-Bordmitteln durchgeführt werden?[/quote]

ja, das geht... ich hab hier mal einen kleinen Hack:

Code: (dl )
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
use test_db_foo_bar;

create table filter (c1 varchar(255));
create table data   (c0 int, c1 varchar(255));

insert into filter (c1)    values ('a b c d');
insert into data   (c0,c1) values (1, 'x x x x');
insert into data   (c0,c1) values (2, 'a x x x');
insert into data   (c0,c1) values (3, 'a b x x');
insert into data   (c0,c1) values (4, 'a b c x');
insert into data   (c0,c1) values (5, 'a b c d');

delimiter //

create procedure demo()
begin
  declare filter_c1,data_c1,str,tmp varchar(255);
  declare len,pos,data_c0,cnt int default 0;
  declare done BOOL default FALSE;
  declare cur1 cursor for select c1 from filter;
  declare cur2 cursor for select c0,c1 from data;
  declare continue handler for not found set done := TRUE;

  open cur1;

  label1: loop

     fetch cur1 into filter_c1;

     if done then
        leave label1;
     end if;

     open cur2;

     label2: loop

        fetch cur2 into data_c0, data_c1;

        if done then
           leave label2;
        end if;

        set tmp = filter_c1;
        set cnt = 0;

        label3: loop

           set pos = instr(tmp, ' ');
           set len = length(tmp);

           if pos = 0 then
              set str = concat('%',tmp,'%');
           else
              set str = concat('%',substr(tmp, 1, pos-1),'%');
           end if;

           set tmp = substr(tmp, pos+1, len);

           if data_c1 like str then
              set cnt = cnt+1;
           end if;

           if cnt = 2 then
              select data_c0, data_c1;
              leave label3;
           end if;

           if pos = 0 then
              leave label3;
           end if;

        end loop label3;

     end loop label2;

     close cur2;

  end loop label1;

  close cur1;
end
//

delimiter;

call demo();


Dieser gibt genau die Zeilen aus, die mindestens zwei Treffer haben:

data_c0 data_c1
3       a b x x
data_c0 data_c1
4       a b c x
data_c0 data_c1
5       a b c d


Ich bin kein Profi, was Prozeduren angeht, aber es funktioniert.

Gruss,
opi\n\n

<!--EDIT|opi|1173966461-->
What is a good module? That's hard to say.
What is good code? That's also hard to say.
One man's Thing of Beauty is another's man's Evil Hack.

View full thread wortgruppen vergleichen