X-Git-Url: http://www.git.stargrave.org/?a=blobdiff_plain;f=lib%2FPublicInbox%2FSearchView.pm;h=36522a3458bffa9121fb4ab598ff9be2f91dbdb4;hb=3cda6050b7c8f73e7fd86f88efc5cd42d0c13f73;hp=9a581561172ddf941ba14a44655497302b77503e;hpb=e22c6b0074928e469866338c4f4e405605cf2b52;p=public-inbox.git diff --git a/lib/PublicInbox/SearchView.pm b/lib/PublicInbox/SearchView.pm index 9a581561..36522a34 100644 --- a/lib/PublicInbox/SearchView.pm +++ b/lib/PublicInbox/SearchView.pm @@ -8,7 +8,7 @@ use warnings; use PublicInbox::SearchMsg; use PublicInbox::Hval; use PublicInbox::View; -use PublicInbox::MID qw(mid2path mid_clean); +use PublicInbox::MID qw(mid2path mid_clean mid_mime); use Email::MIME; require PublicInbox::Git; our $LIM = 50; @@ -35,7 +35,7 @@ sub sres_top_html { my $res = html_start($q, $ctx) . '
';
 	if ($err) {
 		$code = 400;
-		$res .= err_txt($err) . "

" . foot($ctx);
+		$res .= err_txt($ctx, $err) . "

" . foot($ctx);
 	} elsif ($total == 0) {
 		$code = 404;
 		$res .= "\n\n[No results found]

".foot($ctx);
@@ -43,19 +43,21 @@ sub sres_top_html {
 		my $x = $q->{x};
 		return sub { adump($_[0], $mset, $q, $ctx) } if ($x eq 'A');
 
-		$res .= search_nav_top($mset, $q);
+		$res .= search_nav_top($mset, $q) . "\n\n";
 		if ($x eq 't') {
 			return sub { tdump($_[0], $res, $mset, $q, $ctx) };
 		}
-		$res .= "\n\n";
 		dump_mset(\$res, $mset);
-		$res .= search_nav_bot($mset, $q) . "\n\n" . foot($ctx);
+		$res .= '
' . search_nav_bot($mset, $q) . + "\n\n" . foot($ctx); } $res .= ""; [$code, ['Content-Type'=>'text/html; charset=UTF-8'], [$res]]; } +# display non-threaded search results similar to what users expect from +# regular WWW search engines: sub dump_mset { my ($res, $mset) = @_; @@ -78,8 +80,9 @@ sub dump_mset { } sub err_txt { - my ($err) = @_; - my $u = 'http://xapian.org/docs/queryparser.html'; + my ($ctx, $err) = @_; + my $u = '//xapian.org/docs/queryparser.html'; + $u = PublicInbox::Hval::prurl($ctx->{cgi}->{env}, $u); $err =~ s/^\s*Exception:\s*//; # bad word to show users :P $err = PublicInbox::Hval->new_oneline($err)->as_html; "\n\nBad query: $err\n" . @@ -103,16 +106,13 @@ sub search_nav_top { my $x = $q->{x}; if ($x eq '') { my $t = $q->qs_html(x => 't'); - $rv .= qq{summary|}; - $rv .= qq{threaded} + $rv .= qq{summary|threaded} } elsif ($q->{x} eq 't') { my $s = $q->qs_html(x => ''); - $rv .= qq{summary|}; - $rv .= qq{threaded}; + $rv .= qq{summary|threaded}; } my $A = $q->qs_html(x => 'A', r => undef); - $rv .= qq{|Atom}; - $rv .= ']'; + $rv .= qq{|Atom feed]}; } sub search_nav_bot { @@ -141,7 +141,7 @@ sub search_nav_bot { sub tdump { my ($cb, $res, $mset, $q, $ctx) = @_; my $fh = $cb->([200, ['Content-Type'=>'text/html; charset=UTF-8']]); - $fh->write($res); + $fh->write($res .= ''); my %pct; my @m = map { my $i = $_; @@ -171,9 +171,15 @@ sub tdump { } my $git = $ctx->{git} ||= PublicInbox::Git->new($ctx->{git_dir}); - my $state = { ctx => $ctx, anchor_idx => 0, pct => \%pct }; + my $state = { + ctx => $ctx, + anchor_idx => 0, + pct => \%pct, + cur_level => 0 + }; $ctx->{searchview} = 1; tdump_ent($fh, $git, $state, $_, 0) for $th->rootset; + PublicInbox::View::thread_adj_level($fh, $state, 0); Email::Address->purge_cache; $fh->write(search_nav_bot($mset, $q). "\n\n" . @@ -189,17 +195,20 @@ sub tdump_ent { if ($mime) { # lazy load the full message from mini_mime: - my $mid = $mime->header('Message-ID'); + my $mid = mid_mime($mime); $mime = eval { my $path = mid2path(mid_clean($mid)); Email::MIME->new($git->cat_file('HEAD:'.$path)); }; } if ($mime) { + my $end = + PublicInbox::View::thread_adj_level($fh, $state, $level); PublicInbox::View::index_entry($fh, $mime, $level, $state); + $fh->write($end) if $end; } else { my $mid = $node->messageid; - $fh->write(PublicInbox::View::ghost_table('', $mid, $level)); + PublicInbox::View::ghost_flush($fh, $state, '', $mid, $level); } tdump_ent($fh, $git, $state, $node->child, $level + 1); tdump_ent($fh, $git, $state, $node->next, $level); @@ -217,7 +226,8 @@ sub html_start { my $qh = $query->as_html; my $A = $q->qs_html(x => 'A', r => undef); - my $res = "$qh - search results" . + my $res = '' . PublicInbox::Hval::STYLE . + "$qh - search results" . qq{! . qq{} . @@ -235,7 +245,7 @@ sub html_start { sub adump { my ($cb, $mset, $q, $ctx) = @_; my $fh = $cb->([ 200, ['Content-Type' => 'application/atom+xml']]); - my $git = $ctx->{git_dir} ||= PublicInbox::Git->new($ctx->{git_dir}); + my $git = $ctx->{git} ||= PublicInbox::Git->new($ctx->{git_dir}); my $feed_opts = PublicInbox::Feed::get_feedopts($ctx); my $x = PublicInbox::Hval->new_oneline($q->{q})->as_html; $x = qq{$x - search results}; @@ -279,7 +289,7 @@ sub qs_html { $self = $tmp; } - my $q = PublicInbox::Hval->new($self->{q})->as_href; + my $q = PublicInbox::Hval->new_oneline($self->{q})->as_href; $q =~ s/%20/+/g; # improve URL readability my $qs = "q=$q";