X-Git-Url: https://ruin.nu/git/?a=blobdiff_plain;f=NDWeb%2FPages%2FForum%2FSearch.pm;fp=NDWeb%2FPages%2FForum%2FSearch.pm;h=a0f28acff060ad8e03a87ddffaa0d93be9f7b9d1;hb=055f7e12029e85248d4b9ba60d377c1816bce265;hp=0000000000000000000000000000000000000000;hpb=cf3417dbc140a715f503bec5a57af7b30d991a72;p=ndwebbie.git diff --git a/NDWeb/Pages/Forum/Search.pm b/NDWeb/Pages/Forum/Search.pm new file mode 100644 index 0000000..a0f28ac --- /dev/null +++ b/NDWeb/Pages/Forum/Search.pm @@ -0,0 +1,59 @@ +#************************************************************************** +# Copyright (C) 2006 by Michael Andreen * +# * +# This program is free software; you can redistribute it and/or modify * +# it under the terms of the GNU General Public License as published by * +# the Free Software Foundation; either version 2 of the License, or * +# (at your option) any later version. * +# * +# This program is distributed in the hope that it will be useful, * +# but WITHOUT ANY WARRANTY; without even the implied warranty of * +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * +# GNU General Public License for more details. * +# * +# You should have received a copy of the GNU General Public License * +# along with this program; if not, write to the * +# Free Software Foundation, Inc., * +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * +#**************************************************************************/ + +package NDWeb::Pages::Forum::Search; +use strict; +use warnings; +use NDWeb::Forum; +use CGI qw/:standard/; +use NDWeb::Include; +use ND::Include; + +use base qw/NDWeb::Pages::Forum/; + +sub render_body { + my $self = shift; + my ($BODY) = @_; + my $DBH = $self->{DBH}; + $self->{TITLE} = 'Forum'; + + if (param('search')){ + my $posts = $DBH->prepare(q{SELECT fp.ftid,u.username,ft.subject + ,ts_headline(fp.message,to_tsquery($2)) AS headline + ,ts_rank_cd(fp.textsearch, to_tsquery($2),32) AS rank + FROM forum_boards fb + JOIN forum_threads ft USING (fbid) + JOIN forum_posts fp USING (ftid) + JOIN users u ON fp.uid = u.uid + WHERE fb.fbid IN (SELECT fbid FROM forum_access + WHERE gid IN (SELECT groups($1))) + AND fp.textsearch @@@ to_tsquery($2) + ORDER BY rank DESC + }) or warn $DBH->errstr; + $posts->execute($ND::UID,param('search')) or warn $DBH->errstr; + my @posts; + while (my $post = $posts->fetchrow_hashref){ + push @posts,$post; + } + $BODY->param(SearchResult => \@posts); + } + return $BODY; +} + +1;