X-Git-Url: http://www.git.stargrave.org/?a=blobdiff_plain;f=lib%2FPublicInbox%2FSearchView.pm;h=7ef6b075bf60a5b18080f43dafc6380b407258c9;hb=6e6f7999361925e4c944f308df4bc32a1842cd69;hp=3eff7087cc45c642ad1c58f2cc6f22e14f4259b8;hpb=55c13112d18616607d2d3eba159ae18dcb66a568;p=public-inbox.git diff --git a/lib/PublicInbox/SearchView.pm b/lib/PublicInbox/SearchView.pm index 3eff7087..7ef6b075 100644 --- a/lib/PublicInbox/SearchView.pm +++ b/lib/PublicInbox/SearchView.pm @@ -1,5 +1,5 @@ -# Copyright (C) 2015 all contributors -# License: AGPLv3 or later (https://www.gnu.org/licenses/agpl-3.0.txt) +# Copyright (C) 2015-2018 all contributors +# License: AGPL-3.0+ # # Displays search results for the web interface package PublicInbox::SearchView; @@ -10,7 +10,7 @@ use PublicInbox::SearchMsg; use PublicInbox::Hval qw/ascii_html obfuscate_addrs/; use PublicInbox::View; use PublicInbox::WwwAtomStream; -use PublicInbox::MID qw(mid2path mid_mime mid_clean mid_escape MID_ESC); +use PublicInbox::MID qw(MID_ESC); use PublicInbox::MIME; require PublicInbox::Git; require PublicInbox::SearchThread; @@ -18,17 +18,25 @@ our $LIM = 200; sub noop {} +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); +} + sub sres_top_html { my ($ctx) = @_; my $q = PublicInbox::SearchQuery->new($ctx->{qp}); my $x = $q->{x}; my $query = $q->{'q'}; - return PublicInbox::Mbox::mbox_all($ctx, $query) if $x eq 'm'; my $code = 200; # double the limit for expanded views: my $opts = { - limit => $LIM, + limit => $q->{l}, offset => $q->{o}, mset => 1, relevance => $q->{r}, @@ -60,7 +68,7 @@ retry: } else { return adump($_[0], $mset, $q, $ctx) if $x eq 'A'; - $ctx->{-html_tip} = search_nav_top($mset, $q, $ctx) . "\n\n"; + $ctx->{-html_tip} = search_nav_top($mset, $q, $ctx); if ($x eq 't') { $cb = mset_thread($ctx, $mset, $q); } else { @@ -110,11 +118,11 @@ sub mset_summary { obfuscate_addrs($obfs_ibx, $s); obfuscate_addrs($obfs_ibx, $f); } - my $ts = PublicInbox::View::fmt_ts($smsg->ts); + my $date = PublicInbox::View::fmt_ts($smsg->ds); my $mid = PublicInbox::Hval->new_msgid($smsg->mid)->{href}; $$res .= qq{$rank. }. $s . "\n"; - $$res .= "$pfx - by $f @ $ts UTC [$pct%]\n\n"; + $$res .= "$pfx - by $f @ $date UTC [$pct%]\n\n"; } $$res .= search_nav_bot($mset, $q); *noop; @@ -131,8 +139,8 @@ sub err_txt { sub search_nav_top { my ($mset, $q, $ctx) = @_; - - my $rv = '
';
+	my $m = $q->qs_html(x => 'm', r => undef);
+	my $rv = qq{
};
 	my $initial_q = $ctx->{-uxs_retried};
 	if (defined $initial_q) {
 		my $rewritten = $q->{'q'};
@@ -166,17 +174,16 @@ sub search_nav_top {
 	}
 	my $A = $q->qs_html(x => 'A', r => undef);
 	$rv .= qq{|Atom feed]};
-	my $m = $q->qs_html(x => 'm', r => undef);
-	warn "m: $m\n";
-	$rv .= qq{\n\t\t\t\t\t\tdownload: mbox.gz};
+	$rv .= qq{\n\t\t\t\t\t\tdownload: };
+	$rv .= qq{
};
 }
 
 sub search_nav_bot {
 	my ($mset, $q) = @_;
 	my $total = $mset->get_matches_estimated;
-	my $nr = scalar $mset->items;
 	my $o = $q->{o};
-	my $end = $o + $nr;
+	my $l = $q->{l};
+	my $end = $o + $mset->size;
 	my $beg = $o + 1;
 	my $rv = '

';
 	if ($beg <= $end) {
@@ -185,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};
 	}
@@ -221,10 +228,10 @@ sub mset_thread {
 	} ($mset->items) ]});
 	my $r = $q->{r};
 	my $rootset = PublicInbox::SearchThread::thread($msgs,
-		$r ? sort_relevance(\%pct) : *PublicInbox::View::sort_ts,
-		$srch);
+		$r ? sort_relevance(\%pct) : *PublicInbox::View::sort_ds,
+		$ctx);
 	my $skel = search_nav_bot($mset, $q). "
";
-	my $inbox = $ctx->{-inbox};
+	my $ibx = $ctx->{-inbox};
 	$ctx->{-upfx} = '';
 	$ctx->{anchor_idx} = 1;
 	$ctx->{cur_level} = 0;
@@ -233,7 +240,6 @@ sub mset_thread {
 	$ctx->{pct} = \%pct;
 	$ctx->{prev_attr} = '';
 	$ctx->{prev_level} = 0;
-	$ctx->{seen} = {};
 	$ctx->{s_nr} = scalar(@$msgs).'+ results';
 
 	# reduce hash lookups in skel_dump
@@ -242,15 +248,14 @@ sub mset_thread {
 		*PublicInbox::View::pre_thread);
 
 	@$msgs = reverse @$msgs if $r;
-	my $mime;
 	sub {
 		return unless $msgs;
-		while ($mime = pop @$msgs) {
-			$mime = $inbox->msg_by_smsg($mime) and last;
+		my $smsg;
+		while (my $m = pop @$msgs) {
+			$smsg = $ibx->smsg_mime($m) and last;
 		}
-		if ($mime) {
-			$mime = PublicInbox::MIME->new($mime);
-			return PublicInbox::View::index_entry($mime, $ctx,
+		if ($smsg) {
+			return PublicInbox::View::index_entry($smsg, $ctx,
 				scalar @$msgs);
 		}
 		$msgs = undef;
@@ -284,8 +289,7 @@ sub adump {
 	PublicInbox::WwwAtomStream->response($ctx, 200, sub {
 		while (my $x = shift @items) {
 			$x = load_doc_retry($srch, $x);
-			$x = $ibx->msg_by_smsg($x) and
-					return PublicInbox::MIME->new($x);
+			$x = $ibx->smsg_mime($x) and return $x;
 		}
 		return undef;
 	});
@@ -302,10 +306,13 @@ sub new {
 	my ($class, $qp) = @_;
 
 	my $r = $qp->{r};
+	my ($l) = (($qp->{l} || '') =~ /(\d+)/);
+	$l = $LIM if !$l || $l > $LIM;
 	bless {
 		q => $qp->{'q'},
 		x => $qp->{x} || '',
 		o => (($qp->{o} || '0') =~ /(\d+)/),
+		l => $l,
 		r => (defined $r && $r ne '0'),
 	}, $class;
 }
@@ -328,6 +335,9 @@ sub qs_html {
 	if (my $o = $self->{o}) { # ignore o == 0
 		$qs .= "&o=$o";
 	}
+	if (my $l = $self->{l}) {
+		$qs .= "&l=$l" unless $l == $LIM;
+	}
 	if (my $r = $self->{r}) {
 		$qs .= "&r";
 	}