* [PATCH 2/3] searchview: hoist out subroutines for clarity
@ 2015-09-12 1:23 7% ` Eric Wong
0 siblings, 0 replies; 1+ results
From: Eric Wong @ 2015-09-12 1:23 UTC (permalink / raw)
To: meta
We'll be expanding the search view to handle expanded views.
---
lib/PublicInbox/SearchView.pm | 93 +++++++++++++++++++++++++------------------
1 file changed, 55 insertions(+), 38 deletions(-)
diff --git a/lib/PublicInbox/SearchView.pm b/lib/PublicInbox/SearchView.pm
index 13f4de2..82b97f3 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;
--
EW
^ permalink raw reply related [relevance 7%]
Results 1-1 of 1 | reverse | options above
-- pct% links below jump to the message on this page, permalinks otherwise --
2015-09-12 1:23 [PATCH 0/3] enhance search results Eric Wong
2015-09-12 1:23 7% ` [PATCH 2/3] searchview: hoist out subroutines for clarity Eric Wong
Code repositories for project(s) associated with this public inbox
https://80x24.org/public-inbox.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).