X-Git-Url: http://www.git.stargrave.org/?a=blobdiff_plain;f=lib%2FPublicInbox%2FSearchView.pm;h=7ef6b075bf60a5b18080f43dafc6380b407258c9;hb=6e6f7999361925e4c944f308df4bc32a1842cd69;hp=a5974034d20a3335ddc517e50d7b9c3e181b4b98;hpb=1a8eb0a43c68e64b77fdd3c4ebd977a1ab88e71b;p=public-inbox.git diff --git a/lib/PublicInbox/SearchView.pm b/lib/PublicInbox/SearchView.pm index a5974034..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,14 +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 $code = 200; + my $x = $q->{x}; + my $query = $q->{'q'}; + my $code = 200; # double the limit for expanded views: my $opts = { - limit => $LIM, + limit => $q->{l}, offset => $q->{o}, mset => 1, relevance => $q->{r}, @@ -33,7 +44,7 @@ sub sres_top_html { my ($mset, $total, $err, $cb); retry: eval { - $mset = $ctx->{srch}->query($q->{'q'}, $opts); + $mset = $ctx->{srch}->query($query, $opts); $total = $mset->get_matches_estimated; }; $err = $@; @@ -55,10 +66,9 @@ retry: $ctx->{-html_tip} = "
\n[No results found]

"; $cb = *noop; } else { - my $x = $q->{x}; 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 { @@ -79,7 +89,7 @@ sub load_doc_retry { } } -# display non-threaded search results similar to what users expect from +# display non-nested search results similar to what users expect from # regular WWW search engines: sub mset_summary { my ($ctx, $mset, $q) = @_; @@ -108,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; @@ -129,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'};
@@ -157,21 +167,23 @@ sub search_nav_top {
 	my $x = $q->{x};
 	if ($x eq '') {
 		my $t = $q->qs_html(x => 't');
-		$rv .= qq{summary|threaded}
+		$rv .= qq{summary|nested}
 	} elsif ($q->{x} eq 't') {
 		my $s = $q->qs_html(x => '');
-		$rv .= qq{summary|threaded};
+		$rv .= qq{summary|nested};
 	}
 	my $A = $q->qs_html(x => 'A', r => undef);
 	$rv .= qq{|Atom feed]};
+	$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) {
@@ -180,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};
 	}
@@ -207,7 +219,8 @@ sub sort_relevance {
 sub mset_thread {
 	my ($ctx, $mset, $q) = @_;
 	my %pct;
-	my $msgs = $ctx->{srch}->retry_reopen(sub { [ map {
+	my $srch = $ctx->{srch};
+	my $msgs = $srch->retry_reopen(sub { [ map {
 		my $i = $_;
 		my $smsg = PublicInbox::SearchMsg->load_doc($i->get_document);
 		$pct{$smsg->mid} = $i->get_percent;
@@ -215,9 +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);
+		$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;
@@ -226,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
@@ -235,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;
@@ -277,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;
 	});
@@ -295,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;
 }
@@ -321,11 +335,14 @@ 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";
 	}
 	if (my $x = $self->{x}) {
-		$qs .= "&x=$x" if ($x eq 't' || $x eq 'A');
+		$qs .= "&x=$x" if ($x eq 't' || $x eq 'A' || $x eq 'm');
 	}
 	$qs;
 }