SHOW:
|
|
- or go back to the newest paste.
| 1 | drop table if exists question; | |
| 2 | drop table if exists answer; | |
| 3 | create table question(Question text, score int); | |
| 4 | create table answer(answer text, score int); | |
| 5 | ||
| 6 | drop procedure if exists Searching_Answers_Question_g; | |
| 7 | ||
| 8 | delimiter // | |
| 9 | create procedure Searching_Answers_Question_g( in inpute char (200)) | |
| 10 | ||
| 11 | begin | |
| 12 | declare done int default false; | |
| 13 | declare done1 int default false; | |
| 14 | declare a char(200); | |
| 15 | declare b int; | |
| 16 | declare c char(200); | |
| 17 | declare d int; | |
| 18 | ||
| 19 | declare cur1 cursor for (select body, score from (select post_id from (select * from (select post_id as parent_id from (select * from post_tags | |
| 20 | where match(tag_name) against(inpute IN BOOLEAN MODE) ) as t | |
| 21 | natural join post | |
| 22 | where match(post.title) against(+inpute IN BOOLEAN MODE) | |
| 23 | and match(post.body) against(inpute in natural language mode) | |
| 24 | order by post.score desc)as N natural join answer) as S natural join post | |
| 25 | group by parent_id | |
| 26 | having max(post.score)) as ok natural join post); | |
| 27 | ||
| 28 | declare cur2 cursor for(select body, score from (select parent_id as post_id from (select * from (select post_id as parent_id from (select * from post_tags | |
| 29 | where match(tag_name) against(inpute IN BOOLEAN MODE) ) as t | |
| 30 | natural join post | |
| 31 | where match(post.title) against(+inpute IN BOOLEAN MODE) | |
| 32 | and match(post.body) against(inpute in natural language mode) | |
| 33 | order by post.score desc)as N natural join answer) as S natural join post | |
| 34 | group by parent_id | |
| 35 | having max(post.score)) as ok natural join post); | |
| 36 | ||
| 37 | declare continue handler for not found set done = true; | |
| 38 | ||
| 39 | open cur1; | |
| 40 | read_loop: loop | |
| 41 | fetch cur1 into a, b; | |
| 42 | insert into answer values (a,b); | |
| 43 | if done then | |
| 44 | leave read_loop; | |
| 45 | end if; | |
| 46 | end loop; | |
| 47 | close cur1; | |
| 48 | ||
| 49 | open cur2; | |
| 50 | read_loop: loop | |
| 51 | fetch cur2 into c, d; | |
| 52 | insert into question values (c,d); | |
| 53 | if done then | |
| 54 | leave read_loop; | |
| 55 | end if; | |
| 56 | end loop; | |
| 57 | close cur2; | |
| 58 | ||
| 59 | select * from question; | |
| 60 | select * from answer; | |
| 61 | ||
| 62 | drop table if exists question; | |
| 63 | drop table if exists answer; | |
| 64 | ||
| 65 | end; | |
| 66 | //delimiter ; | |
| 67 | ||
| 68 | -- call Searching_Answers_Question_g('python');
| |
| 69 | call Searching_Answers_Question_g('how to program in python'); |