From: Eric Wong <e@80x24.org>
To: meta@public-inbox.org
Subject: [PATCH 2/3] searchview: hoist out subroutines for clarity
Date: Sat, 12 Sep 2015 01:23:31 +0000 [thread overview]
Message-ID: <20150912012332.1542-3-e@80x24.org> (raw)
In-Reply-To: <20150912012332.1542-1-e@80x24.org>
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
next prev parent reply other threads:[~2015-09-12 1:23 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-09-12 1:23 [PATCH 0/3] enhance search results Eric Wong
2015-09-12 1:23 ` [PATCH 1/3] view: more consistent prefix for ghost links Eric Wong
2015-09-12 1:23 ` Eric Wong [this message]
2015-09-12 1:23 ` [PATCH 3/3] searchview: support displaying entire threads Eric Wong
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://public-inbox.org/README
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20150912012332.1542-3-e@80x24.org \
--to=e@80x24.org \
--cc=meta@public-inbox.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).