unofficial mirror of meta@public-inbox.org
 help / color / mirror / Atom feed
* [PATCH v2]
@ 2018-03-30 21:25 Jonathan Corbet
  2018-04-01 23:21 ` [PATCH v2] Allow specification of the number of search results to return Eric Wong
  0 siblings, 1 reply; 3+ messages in thread
From: Jonathan Corbet @ 2018-03-30 21:25 UTC (permalink / raw)
  To: meta

Allow specification of the number of search results to return

Add an "l=" parameter to the search query syntax to specify how many
results should be returned.
---
v2: Clamp the number of results at $LIM (200).  I didn't add a
configurable maximum because I wouldn't be using it; if somebody needs it
we can add it later.

 lib/PublicInbox/SearchView.pm | 17 +++++++++++++---- 
 1 file changed, 13 insertions(+), 4 deletions(-)

diff --git a/lib/PublicInbox/SearchView.pm b/lib/PublicInbox/SearchView.pm
index 53b88c3..bf4415f 100644
--- a/lib/PublicInbox/SearchView.pm
+++ b/lib/PublicInbox/SearchView.pm
@@ -35,7 +35,7 @@ sub sres_top_html {
 	my $code = 200;
 	# double the limit for expanded views:
 	my $opts = {
-		limit => $LIM,
+		limit => $q->{l},
 		offset => $q->{o},
 		mset => 1,
 		relevance => $q->{r},
@@ -182,6 +182,7 @@ sub search_nav_bot {
 	my $total = $mset->get_matches_estimated;
 	my $nr = scalar $mset->items;
 	my $o = $q->{o};
+	my $l = $q->{l};
 	my $end = $o + $nr;
 	my $beg = $o + 1;
 	my $rv = '</pre><hr><pre id=t>';
@@ -191,15 +192,15 @@ sub search_nav_bot {
 	} else {
 		$rv .= "No more results, only $total";
 	}
-	my $n = $o + $LIM;
+	my $n = $o + $l;
 
 	if ($n < $total) {
-		my $qs = $q->qs_html(o => $n);
+		my $qs = $q->qs_html(o => $n, l => $l);
 		$rv .= qq{  <a\nhref="?$qs"\nrel=next>next</a>}
 	}
 	if ($o > 0) {
 		$rv .= $n < $total ? '/' : '       ';
-		my $p = $o - $LIM;
+		my $p = $o - $l;
 		my $qs = $q->qs_html(o => ($p > 0 ? $p : 0));
 		$rv .= qq{<a\nhref="?$qs"\nrel=prev>prev</a>};
 	}
@@ -308,10 +309,15 @@ sub new {
 	my ($class, $qp) = @_;
 
 	my $r = $qp->{r};
+	my $l = $qp->{l} || '200';
+	if (! ($l =~ /(\d+)/ && $l <= $LIM)) {
+		$l = $LIM;
+	}
 	bless {
 		q => $qp->{'q'},
 		x => $qp->{x} || '',
 		o => (($qp->{o} || '0') =~ /(\d+)/),
+		l => $l,
 		r => (defined $r && $r ne '0'),
 	}, $class;
 }
@@ -334,6 +340,9 @@ sub qs_html {
 	if (my $o = $self->{o}) { # ignore o == 0
 		$qs .= "&amp;o=$o";
 	}
+	if (my $l = $self->{l}) {
+		$qs .= "&amp;l=$l";
+	}
 	if (my $r = $self->{r}) {
 		$qs .= "&amp;r";
 	}
-- 
2.14.3


^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2018-04-01 23:22 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-03-30 21:25 [PATCH v2] Jonathan Corbet
2018-04-01 23:21 ` [PATCH v2] Allow specification of the number of search results to return Eric Wong
2018-04-01 23:22   ` [PATCH] searchview: fix non-numeric comparison Eric Wong

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