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
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;
-<form action="/<TMPL_VAR NAME=PAGE>" method="post"><fieldset class="forum-post"> <legend>Search</legend>
+<form action="/<TMPL_VAR NAME=PAGE>" method="post">
+
+<fieldset class="forum-post"> <legend>Topic</legend>
+ Find posts with these words in the thread's topic<br/>
+ <input style="width:98%" type="text" name="topic" value=""/><br/>
+ Require all words: <input type="checkbox" name="alltopic" value="1"/><br/>
+</fieldset>
+
+<fieldset class="forum-post"> <legend>Body</legend>
+ Find posts with these words in the body<br/>
+ <input style="width:98%" type="text" name="body" value=""/><br/>
+ Require all words: <input type="checkbox" name="allbody" value="1"/><br/>
+</fieldset>
+
+<fieldset class="forum-post"> <legend>Usernames</legend>
+ Find posts written by one these users<br/>
+ <input style="width:98%" type="text" name="author" value=""/><br/>
+</fieldset>
+
+<fieldset class="forum-post"> <legend>Custom search</legend>
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.
- <p>Search query: <input type="text" name="search" value=""/></p>
- <input type="submit" name="cmd" value="Search"/>
-</fieldset></form>
+ <p><input style="width:98%" type="text" name="search" value=""/></p>
+</fieldset>
+<input type="submit" name="cmd" value="Search"/>
+</form>
<TMPL_IF SearchResult>
<table>