From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: AS63949 45.79.64.0/19 X-Spam-Status: No, score=-3.0 required=3.0 tests=BAYES_00,RCVD_IN_DNSWL_NONE, SPF_PASS,T_RP_MATCHES_RCVD shortcircuit=no autolearn=ham autolearn_force=no version=3.4.0 Received: from ms.lwn.net (ms.lwn.net [45.79.88.28]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by dcvr.yhbt.net (Postfix) with ESMTPS id A8C751F404 for ; Fri, 30 Mar 2018 21:25:59 +0000 (UTC) Received: from lwn.net (localhost [127.0.0.1]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ms.lwn.net (Postfix) with ESMTPSA id CAF96AAB for ; Fri, 30 Mar 2018 21:25:58 +0000 (UTC) Date: Fri, 30 Mar 2018 15:25:57 -0600 From: Jonathan Corbet To: meta@public-inbox.org Subject: [PATCH v2] Message-ID: <20180330152557.1604c836@lwn.net> Organization: LWN.net MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 8bit List-Id: 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 = '
';
@@ -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{  next}
 	}
 	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{prev};
 	}
@@ -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 .= "&o=$o";
 	}
+	if (my $l = $self->{l}) {
+		$qs .= "&l=$l";
+	}
 	if (my $r = $self->{r}) {
 		$qs .= "&r";
 	}
-- 
2.14.3