From: Michael Andreen Date: Tue, 12 Aug 2008 15:36:43 +0000 (+0200) Subject: Added wiki search. X-Git-Url: https://ruin.nu/git/?p=ndwebbie.git;a=commitdiff_plain;h=07cc5bb211b600980b44cb28ec892a6cdd109437 Added wiki search. Both simple and more advanced search available. Only searches pages the user has access to. --- diff --git a/lib/NDWeb/Controller/Wiki.pm b/lib/NDWeb/Controller/Wiki.pm index d15c609..1792fa1 100644 --- a/lib/NDWeb/Controller/Wiki.pm +++ b/lib/NDWeb/Controller/Wiki.pm @@ -152,6 +152,40 @@ sub postedit : Local { $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; diff --git a/root/lib/site/leftbar.tt2 b/root/lib/site/leftbar.tt2 index 8f42cfe..96d7cbc 100644 --- a/root/lib/site/leftbar.tt2 +++ b/root/lib/site/leftbar.tt2 @@ -2,6 +2,14 @@ [% IF c.check_user_roles("member_menu") %]
  • Main page
  • [% END %]
  • Wiki
  • +
  • +
    +

    + + +

    +
    +
  • Forum
  • Forum search
  • [% IF user %] diff --git a/root/src/wiki/search.tt2 b/root/src/wiki/search.tt2 new file mode 100644 index 0000000..20bc49a --- /dev/null +++ b/root/src/wiki/search.tt2 @@ -0,0 +1,37 @@ +[% META title = 'Wiki search' %] + +
    + +
    Wiki search +

    + +

    Use advanced search:

    + + 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. +
    +

    +
    + +[% IF searcherror %] +

    Could not search, because of:

    +

    [% searcherror | html %]

    +[% END %] + +[% IF searchresults %] + + + + + + + [% FOR p IN searchresults %] + + + + + + [% END %] +
    PageMessageRank
     [% p.fullname %] [% p.headline %][% p.rank %]
    +[% END %]