diff options
author | Eric Wong <e@80x24.org> | 2015-09-12 01:23:31 +0000 |
---|---|---|
committer | Eric Wong <e@80x24.org> | 2015-09-12 01:24:10 +0000 |
commit | 3fcca93c1391c570e71a81f9467b95d7fcd1910e (patch) | |
tree | df4b48e160a88103308d75274998c00c0df1fc45 /lib/PublicInbox/SearchView.pm | |
parent | 930f2746d48829af6ca8b14ba96e006204fae4d5 (diff) | |
download | public-inbox-3fcca93c1391c570e71a81f9467b95d7fcd1910e.tar.gz |
We'll be expanding the search view to handle expanded views.
Diffstat (limited to 'lib/PublicInbox/SearchView.pm')
-rw-r--r-- | lib/PublicInbox/SearchView.pm | 93 |
1 files changed, 55 insertions, 38 deletions
diff --git a/lib/PublicInbox/SearchView.pm b/lib/PublicInbox/SearchView.pm index 13f4de2a..82b97f32 100644 --- a/lib/PublicInbox/SearchView.pm +++ b/lib/PublicInbox/SearchView.pm @@ -38,52 +38,19 @@ sub sres_top_html { my $foot = $ctx->{footer} || ''; $foot = qq{Back to <a\nhref=".">index</a>.}; if ($err) { - my $u = 'http://xapian.org/docs/queryparser.html'; $code = 400; - $err =~ s/^\s*Exception:\s*//; # bad word to show users :P - $err = PublicInbox::Hval->new_oneline($err)->as_html; - $res .= "\n\nBad query: <b>$err</b>\n"; - $res .= qq{See <a\nhref="$u">$u</a> for Xapian query syntax}; - $res .= "</pre><hr /><pre>$foot"; + $res .= err_txt($err) . "</pre><hr /><pre>$foot"; } elsif ($total == 0) { $code = 404; $res .= "\n\n[No results found]</pre><hr /><pre>$foot"; } else { $q = $query->as_href; $q =~ s/%20/+/g; # improve URL readability - my $qp = "?q=$q"; - $qp .= "&o=$o" if $o; + $res .= search_nav_top($q, $o, $r); + $res .= "\n\n"; - $res .= "Search results ordered by ["; - if ($r) { - $res .= qq{<a\nhref="$qp">date</a>|<b>relevance</b>}; - } else { - $qp .= '&r'; - $res .= qq{<b>date</b>|<a\nhref="$qp">relevance</a>}; - } - $res .= "]\n\n"; - - dump_mset(\$res, $mset); - my $nr = scalar $mset->items; - my $end = $o + $nr; - my $beg = $o + 1; - $res .= "<hr /><pre>"; - $res .= "Results $beg-$end of $total"; - - my $n = $o + $LIM; - if ($n < $total) { - $qp = "q=$q&o=$n"; - $qp .= "&r" if $r; - $res .= qq{, <a\nhref="?$qp">next</a>} - } - if ($o > 0) { - $res .= $n < $total ? '/' : ', '; - my $p = $o - $LIM; - $qp = "q=$q"; - $qp .= "&o=$p" if $p > 0; - $qp .= "&r" if $r; - $res .= qq{<a\nhref="?$qp">prev</a>}; - } + dump_mset(\$res, $mset, $o); + $res .= search_nav_bot($mset, $q, $o, $r); $res .= "\n\n" . $foot; } @@ -112,4 +79,54 @@ sub dump_mset { } } +sub err_txt { + my ($err) = @_; + my $u = 'http://xapian.org/docs/queryparser.html'; + $err =~ s/^\s*Exception:\s*//; # bad word to show users :P + $err = PublicInbox::Hval->new_oneline($err)->as_html; + "\n\nBad query: <b>$err</b>\n" . + qq{See <a\nhref="$u">$u</a> for Xapian query syntax}; +} + +sub search_nav_top { + my ($q, $o, $r) = @_; + my $qs = "q=$q"; + $qs .= "&o=$o" if $o; + + my $rv = "Search results ordered by ["; + if ($r) { + $rv .= qq{<a\nhref="?$qs">date</a>|<b>relevance</b>}; + } else { + $qs .= '&r'; + $rv .= qq{<b>date</b>|<a\nhref="?$qs">relevance</a>}; + } + $rv .= ']'; +} + +sub search_nav_bot { + my ($mset, $q, $o, $r) = @_; + my $total = $mset->get_matches_estimated; + my $nr = scalar $mset->items; + my $end = $o + $nr; + my $beg = $o + 1; + + my $rv = "<hr /><pre>Results $beg-$end of $total"; + + my $n = $o + $LIM; + if ($n < $total) { + my $qs = "q=$q&o=$n"; + $qs .= "&r" if $r; + $rv .= qq{, <a\nhref="?$qs">next</a>} + } + if ($o > 0) { + $rv .= $n < $total ? '/' : ', '; + my $p = $o - $LIM; + my $qs = "q=$q"; + $qs .= "&o=$p" if $p > 0; + $qs .= "&r" if $r; + $rv .= qq{<a\nhref="?$qs">prev</a>}; + } + $rv; +} + 1; |