From f091970c5fb3cb60583c1d00aaef3b00191feacb Mon Sep 17 00:00:00 2001 From: Michael Andreen Date: Sun, 2 Mar 2008 17:43:22 +0100 Subject: [PATCH] Slightly more userfriendy search --- NDWeb/Pages/Forum/Search.pm | 19 +++++++++++++++++-- templates/forum/search.tmpl | 28 ++++++++++++++++++++++++---- 2 files changed, 41 insertions(+), 6 deletions(-) diff --git a/NDWeb/Pages/Forum/Search.pm b/NDWeb/Pages/Forum/Search.pm index a0f28ac..1789bc7 100644 --- a/NDWeb/Pages/Forum/Search.pm +++ b/NDWeb/Pages/Forum/Search.pm @@ -32,8 +32,23 @@ sub render_body { my ($BODY) = @_; my $DBH = $self->{DBH}; $self->{TITLE} = 'Forum'; - + my @queries; if (param('search')){ + push @queries,'('.param('search').')'; + } + my %cat = (body => 'D', topic => 'A', author => 'B'); + for ('body','topic','author'){ + if (param($_)){ + my @words = split /\W+/,param($_); + my $op = param('all'.$_) ? '&' : '|'; + my $cat = $cat{$_}; + my $query = join " $op ", map {"$_:$cat"} @words; + push @queries,"($query)"; + } + } + my $search = join ' & ', @queries; + + if ($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 @@ -46,7 +61,7 @@ sub render_body { AND fp.textsearch @@@ to_tsquery($2) ORDER BY rank DESC }) or warn $DBH->errstr; - $posts->execute($ND::UID,param('search')) or warn $DBH->errstr; + $posts->execute($ND::UID,$search) or warn escapeHTML $DBH->errstr; my @posts; while (my $post = $posts->fetchrow_hashref){ push @posts,$post; diff --git a/templates/forum/search.tmpl b/templates/forum/search.tmpl index f631724..43890f4 100644 --- a/templates/forum/search.tmpl +++ b/templates/forum/search.tmpl @@ -1,10 +1,30 @@ -
Search + + +
Topic + Find posts with these words in the thread's topic
+
+ Require all words:
+
+ +
Body + Find posts with these words in the body
+
+ Require all words:
+
+ +
Usernames + Find posts written by one these users
+
+
+ +
Custom search Use | (OR) or & (AND) to separate words. Word:A searches for Word in topic and Word:B searches for Word as author. 'Two words' to search for a longer string. Word:D limits the search to just the message body. -

Search query:

- -
+

+
+ + -- 2.39.2