]> ruin.nu Git - ndwebbie.git/commitdiff
Slightly more userfriendy search
authorMichael Andreen <harv@ruin.nu>
Sun, 2 Mar 2008 16:43:22 +0000 (17:43 +0100)
committerMichael Andreen <harv@ruin.nu>
Sun, 2 Mar 2008 16:43:22 +0000 (17:43 +0100)
NDWeb/Pages/Forum/Search.pm
templates/forum/search.tmpl

index a0f28acff060ad8e03a87ddffaa0d93be9f7b9d1..1789bc71760f7502133a7380b1f49d2ea469a0dd 100644 (file)
@@ -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;
index f63172466c8dca17ecf1d86a8f4523a541846a29..43890f48d63535c2e1ae4768f169e93d16f96e42 100644 (file)
@@ -1,10 +1,30 @@
-<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 &amp; (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>