user/dev discussion of public-inbox itself
 help / color / mirror / code / 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

* [PATCH v2] Allow specification of the number of search results to return
  2018-03-30 21:25 [PATCH v2] Jonathan Corbet
@ 2018-04-01 23:21 ` Eric Wong
  2018-04-01 23:22   ` [PATCH] searchview: fix non-numeric comparison Eric Wong
  0 siblings, 1 reply; 3+ messages in thread
From: Eric Wong @ 2018-04-01 23:21 UTC (permalink / raw)
  To: Jonathan Corbet; +Cc: meta

Jonathan Corbet <corbet@lwn.net> wrote:
> Allow specification of the number of search results to return

Interesting, now I've learned git-am treats that as the commit
title since the Subject was empty.  Doesn't look that great in
my MUA or public-inbox, though.

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

Sure, that's fine.  I prefer having fewer knobs overall.
I noticed another minor problem, but will followup in a separate
patch.

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

* [PATCH] searchview: fix non-numeric comparison
  2018-04-01 23:21 ` [PATCH v2] Allow specification of the number of search results to return Eric Wong
@ 2018-04-01 23:22   ` Eric Wong
  0 siblings, 0 replies; 3+ messages in thread
From: Eric Wong @ 2018-04-01 23:22 UTC (permalink / raw)
  To: meta; +Cc: Jonathan Corbet

Eric Wong <e@80x24.org> wrote:
> I noticed another minor problem, but will followup in a separate
> patch.

Subject: [PATCH] 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 ++----
 t/psgi_search.t               | 6 ++++++
 2 files changed, 8 insertions(+), 4 deletions(-)

diff --git a/lib/PublicInbox/SearchView.pm b/lib/PublicInbox/SearchView.pm
index bf4415f..219006a 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} || '',
diff --git a/t/psgi_search.t b/t/psgi_search.t
index 1df3869..84b3daa 100644
--- a/t/psgi_search.t
+++ b/t/psgi_search.t
@@ -64,6 +64,12 @@ test_psgi(sub { $www->call(@_) }, sub {
 	is('%C3%86var', (keys %uniq)[0], 'matches original query');
 	ok(index($html, 'by &#198;var Arnfj&#246;r&#240; Bjarmason') >= 0,
 		"displayed Ævar's name properly in HTML");
+
+	my $warn = [];
+	local $SIG{__WARN__} = sub { push @$warn, @_ };
+	$res = $cb->(GET('/test/?q=s:test&l=5e'));
+	is($res->code, 200, 'successful search result');
+	is_deeply([], $warn, 'no warnings from non-numeric comparison');
 });
 
 done_testing();
-- 
EW

^ 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

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