]> ruin.nu Git - ndwebbie.git/blob - NDWeb/Pages/Forum/Search.pm
Basic forum search
[ndwebbie.git] / NDWeb / Pages / Forum / Search.pm
1 #**************************************************************************
2 #   Copyright (C) 2006 by Michael Andreen <harvATruinDOTnu>               *
3 #                                                                         *
4 #   This program is free software; you can redistribute it and/or modify  *
5 #   it under the terms of the GNU General Public License as published by  *
6 #   the Free Software Foundation; either version 2 of the License, or     *
7 #   (at your option) any later version.                                   *
8 #                                                                         *
9 #   This program is distributed in the hope that it will be useful,       *
10 #   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
11 #   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
12 #   GNU General Public License for more details.                          *
13 #                                                                         *
14 #   You should have received a copy of the GNU General Public License     *
15 #   along with this program; if not, write to the                         *
16 #   Free Software Foundation, Inc.,                                       *
17 #   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.         *
18 #**************************************************************************/
19
20 package NDWeb::Pages::Forum::Search;
21 use strict;
22 use warnings;
23 use NDWeb::Forum;
24 use CGI qw/:standard/;
25 use NDWeb::Include;
26 use ND::Include;
27
28 use base qw/NDWeb::Pages::Forum/;
29
30 sub render_body {
31         my $self = shift;
32         my ($BODY) = @_;
33         my $DBH = $self->{DBH};
34         $self->{TITLE} = 'Forum';
35
36         if (param('search')){
37                 my $posts = $DBH->prepare(q{SELECT fp.ftid,u.username,ft.subject
38                         ,ts_headline(fp.message,to_tsquery($2)) AS headline
39                         ,ts_rank_cd(fp.textsearch, to_tsquery($2),32) AS rank
40                         FROM forum_boards fb 
41                                 JOIN forum_threads ft USING (fbid)
42                                 JOIN forum_posts fp USING (ftid)
43                                 JOIN users u ON fp.uid = u.uid
44                         WHERE fb.fbid IN (SELECT fbid FROM forum_access 
45                                         WHERE gid IN (SELECT groups($1)))
46                                 AND fp.textsearch @@@ to_tsquery($2)
47                         ORDER BY rank DESC
48                 }) or warn $DBH->errstr;
49                 $posts->execute($ND::UID,param('search')) or warn $DBH->errstr;
50                 my @posts;
51                 while (my $post = $posts->fetchrow_hashref){
52                         push @posts,$post;
53                 }
54                 $BODY->param(SearchResult => \@posts);
55         }
56         return $BODY;
57 }
58
59 1;