user/dev discussion of public-inbox itself
 help / color / mirror / code / Atom feed
From: Eric Wong <e@80x24.org>
To: meta@public-inbox.org
Subject: [PATCH] searchview: improve footer navigation
Date: Sat,  5 Sep 2015 06:19:29 +0000	[thread overview]
Message-ID: <1441433969-9482-1-git-send-email-e@80x24.org> (raw)

Aallow navigating backwards and forwards, as some pages will be
bookmarked or some browsers may not have history.  Also add a
link back to the index where they presumably came from.

While we're at it, limit the number of results we have to 25
for now to avoid making the page too big and wasting clients
memory for irrelevant results.
---
 lib/PublicInbox/SearchView.pm | 28 +++++++++++++++++++---------
 1 file changed, 19 insertions(+), 9 deletions(-)

diff --git a/lib/PublicInbox/SearchView.pm b/lib/PublicInbox/SearchView.pm
index 6113bbf..4d49d25 100644
--- a/lib/PublicInbox/SearchView.pm
+++ b/lib/PublicInbox/SearchView.pm
@@ -7,6 +7,7 @@ use PublicInbox::SearchMsg;
 use PublicInbox::Hval;
 use PublicInbox::View;
 use POSIX qw/strftime/;
+our $LIM = 25;
 
 sub sres_top_html {
 	my ($ctx, $q) = @_;
@@ -15,7 +16,7 @@ sub sres_top_html {
 	my $o = int($cgi->param('o') || 0);
 	my $r = $cgi->param('r');
 	$r = (defined $r && $r ne '0');
-	my $opts = { offset => $o, mset => 1, relevance => $r };
+	my $opts = { limit => $LIM, offset => $o, mset => 1, relevance => $r };
 	my $mset = $ctx->{srch}->query($q, $opts);
 	my $total = $mset->get_matches_estimated;
 	my $query = PublicInbox::Hval->new_oneline($q);
@@ -29,9 +30,9 @@ sub sres_top_html {
 	$res .= qq{<input\ntype=submit\nvalue=search /></form>} .
 		  PublicInbox::View::PRE_WRAP;
 
-	my $foot = $ctx->{footer};
+	my $foot = $ctx->{footer} || '';
+	$foot = qq{Back to <a\nhref=".">index</a>.};
 	if ($total == 0) {
-		$foot ||= '';
 		$res .= "\n\n[No results found]</pre><hr /><pre>$foot";
 	} else {
 		$q = $query->as_href;
@@ -69,14 +70,23 @@ sub sres_top_html {
 		my $end = $o + $nr;
 		my $beg = $o + 1;
 		$res .= "<hr /><pre>";
-		$res .= "Results $beg-$end of $total.";
-		if ($nr < $total) {
-			$o = $o + $nr;
-			$qp = "q=$q&amp;o=$o";
+		$res .= "Results $beg-$end of $total";
+
+		my $n = $o + $LIM;
+		if ($n < $total) {
+			$qp = "q=$q&amp;o=$n";
+			$qp .= "&amp;r" if $r;
+			$res .= qq{, <a\nhref="?$qp">next</a>}
+		}
+		if ($o > 0) {
+			$res .= $n < $total ? '/' : ',      ';
+			my $p = $o - $LIM;
+			$qp = "q=$q";
+			$qp .= "&amp;o=$p" if $p > 0;
 			$qp .= "&amp;r" if $r;
-			$res .= qq{ <a\nhref="?$qp">more</a>}
+			$res .= qq{<a\nhref="?$qp">prev</a>};
 		}
-		$res .= "\n\n".$foot if $foot;
+		$res .= "\n\n".$foot;
 	}
 
 	$res .= "</pre></body></html>";
-- 
EW


                 reply	other threads:[~2015-09-05  6:19 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=1441433969-9482-1-git-send-email-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.
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).