From 051a182852a9eef8b0dc8714c81293daded1d4dc Mon Sep 17 00:00:00 2001 From: Jonathan Corbet Date: Fri, 30 Mar 2018 15:25:57 -0600 Subject: 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. --- lib/PublicInbox/SearchView.pm | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) (limited to 'lib/PublicInbox/SearchView.pm') diff --git a/lib/PublicInbox/SearchView.pm b/lib/PublicInbox/SearchView.pm index 53b88c34..bf4415f0 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";
 	}
-- 
cgit v1.2.3-24-ge0c7


From 3f3d9cf7d88a851721f1f8468e1311a4f0c02ff6 Mon Sep 17 00:00:00 2001
From: Eric Wong 
Date: Sun, 1 Apr 2018 22:58:19 +0000
Subject: searchview: fix non-numeric comparison

We don't want non-fully-numeric limits being compared and
tripping warnings.  While we're at it, avoid hard-coding
'200' and reuse $LIM as the default.
---
 lib/PublicInbox/SearchView.pm | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)

(limited to 'lib/PublicInbox/SearchView.pm')

diff --git a/lib/PublicInbox/SearchView.pm b/lib/PublicInbox/SearchView.pm
index bf4415f0..219006a0 100644
--- a/lib/PublicInbox/SearchView.pm
+++ b/lib/PublicInbox/SearchView.pm
@@ -309,10 +309,8 @@ sub new {
 	my ($class, $qp) = @_;
 
 	my $r = $qp->{r};
-	my $l = $qp->{l} || '200';
-	if (! ($l =~ /(\d+)/ && $l <= $LIM)) {
-		$l = $LIM;
-	}
+	my ($l) = (($qp->{l} || '') =~ /(\d+)/);
+	$l = $LIM if !$l || $l > $LIM;
 	bless {
 		q => $qp->{'q'},
 		x => $qp->{x} || '',
-- 
cgit v1.2.3-24-ge0c7


From 15eb65ffd59c7cf5cce67c6b7621f63194fd1083 Mon Sep 17 00:00:00 2001
From: Eric Wong 
Date: Tue, 3 Apr 2018 10:34:54 +0000
Subject: mbox: do not barf on queries which return no results

Having zero search results means we never get a chance
to populate the Content-Disposition header for mbox
downloads.
---
 lib/PublicInbox/SearchView.pm | 1 +
 1 file changed, 1 insertion(+)

(limited to 'lib/PublicInbox/SearchView.pm')

diff --git a/lib/PublicInbox/SearchView.pm b/lib/PublicInbox/SearchView.pm
index 219006a0..1c4442e4 100644
--- a/lib/PublicInbox/SearchView.pm
+++ b/lib/PublicInbox/SearchView.pm
@@ -22,6 +22,7 @@ sub mbox_results {
 	my ($ctx) = @_;
 	my $q = PublicInbox::SearchQuery->new($ctx->{qp});
 	my $x = $q->{x};
+	require PublicInbox::Mbox;
 	return PublicInbox::Mbox::mbox_all($ctx, $q->{'q'}) if $x eq 'm';
 	sres_top_html($ctx);
 }
-- 
cgit v1.2.3-24-ge0c7