Both simple and more advanced search available.
Only searches pages the user has access to.
$c->stash(template => 'wiki/edit.tt2');
}
+sub search : Local {
+ my ( $self, $c ) = @_;
+ my $dbh = $c->model;
+
+ if ($c->req->param('search')){
+ $c->stash(search => $c->req->param('search'));
+ my $queryfunc = 'plainto_tsquery';
+ $queryfunc = 'to_tsquery' if $c->req->param('advsearch');
+ my $posts = $dbh->prepare(q{SELECT wp.wpid,namespace,name
+ ,(CASE WHEN namespace <> '' THEN namespace || ':' ELSE '' END) || name AS fullname
+ ,ts_headline(wpr.text,}.$queryfunc.q{($2)) AS headline
+ ,ts_rank_cd(textsearch, }.$queryfunc.q{($2),32) AS rank
+ FROM wiki_pages wp
+ JOIN wiki_page_revisions wpr USING (wprev)
+ WHERE (namespace IN (SELECT namespace FROM wiki_namespace_access WHERE gid IN (SELECT groups($1)))
+ OR wp.wpid IN (SELECT wpid FROM wiki_page_access WHERE uid = $1))
+ AND textsearch @@ }.$queryfunc.q{($2)
+ ORDER BY rank DESC
+ });
+ eval {
+ $posts->execute($c->stash->{UID},$c->req->param('search'));
+ my @posts;
+ while (my $post = $posts->fetchrow_hashref){
+ push @posts,$post;
+ }
+ $c->stash(searchresults => \@posts);
+ };
+ if ($@){
+ $c->stash( searcherror => $dbh->errstr);
+ }
+ }
+
+}
+
sub findPage : Private {
my ( $self, $c, $p ) = @_;
my $dbh = $c->model;
[% IF c.check_user_roles("member_menu") %]<li><a href="/members">Main page</a></li>[% END %]
<li><a href="/wiki">Wiki</a></li>
+ <li>
+ <form action="/wiki/search" method="post">
+ <p>
+ <input type="text" name="search" value="">
+ <input type="submit" value="Wiki search">
+ </p>
+ </form>
+ </li>
<li><a href="/forum">Forum</a></li>
<li><a href="/forum/search">Forum search</a></li>
[% IF user %]
--- /dev/null
+[% META title = 'Wiki search' %]
+
+<form action="[% c.uri_for('search') %]" method="post">
+
+<fieldset class="forum-post"> <legend>Wiki search</legend>
+ <p><input style="width:98%" type="text" name="search" value="[% search %]"></p>
+
+ <p>Use advanced search: <input type="checkbox" name="advsearch"></p>
+
+ Advanced search has the following syntax:
+ Use | (OR) or & (AND) to separate words. Word:A searches for Word in
+ topic 'Two words' to search for a longer string. Word:D limits the search to just the message body.
+</fieldset>
+<p><input type="submit" name="cmd" value="Search"></p>
+</form>
+
+[% IF searcherror %]
+<p> Could not search, because of: </p>
+<p> [% searcherror | html %] </p>
+[% END %]
+
+[% IF searchresults %]
+<table>
+<tr>
+ <th>Page</th>
+ <th>Message</th>
+ <th>Rank</th>
+</tr>
+ [% FOR p IN searchresults %]
+ <tr align="left" class="[% IF loop.count % 2 == 0 %]even[% ELSE %]odd[% END %]">
+ <td><a href="[% c.uri_for('',p.fullname) %]"> [% p.fullname %] </a></td>
+ <td align="center">[% p.headline %]</td>
+ <td>[% p.rank %]</td>
+ </tr>
+ [% END %]
+</table>
+[% END %]