X-Git-Url: http://www.git.stargrave.org/?a=blobdiff_plain;f=lib%2FPublicInbox%2FSearchView.pm;h=0ae050529ca0601da056463b11ab5acece6ccf25;hb=23a4e44bedabe5b8b651346cabc2a870c5377a30;hp=8751fca29654e7d51cfd6b952dc25c98e75ccff2;hpb=5d6c424d03a4057b129f4e5e099e378376a63e85;p=public-inbox.git diff --git a/lib/PublicInbox/SearchView.pm b/lib/PublicInbox/SearchView.pm index 8751fca2..0ae05052 100644 --- a/lib/PublicInbox/SearchView.pm +++ b/lib/PublicInbox/SearchView.pm @@ -6,11 +6,12 @@ package PublicInbox::SearchView; use strict; use warnings; use PublicInbox::SearchMsg; -use PublicInbox::Hval; +use PublicInbox::Hval qw/ascii_html/; 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; +require PublicInbox::Thread; our $LIM = 50; sub sres_top_html { @@ -35,7 +36,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); @@ -56,6 +57,8 @@ sub sres_top_html { [$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) = @_; @@ -66,22 +69,22 @@ sub dump_mset { my $rank = sprintf("%${pad}d", $m->get_rank + 1); my $pct = $m->get_percent; my $smsg = PublicInbox::SearchMsg->load_doc($m->get_document); - my $s = PublicInbox::Hval->new_oneline($smsg->subject); - my $f = $smsg->from_name; - $f = PublicInbox::Hval->new_oneline($f)->as_html; + my $s = ascii_html($smsg->subject); + my $f = ascii_html($smsg->from_name); my $ts = PublicInbox::View::fmt_ts($smsg->ts); my $mid = PublicInbox::Hval->new_msgid($smsg->mid)->as_href; $$res .= qq{$rank. }. - $s->as_html . "\n"; + $s . "\n"; $$res .= "$pfx - by $f @ $ts UTC [$pct%]\n\n"; } } 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; + $err = ascii_html($err); "\n\nBad query: $err\n" . qq{See $u for Xapian query syntax}; } @@ -103,15 +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 .= qq{|Atom feed]}; } sub search_nav_bot { @@ -126,13 +127,13 @@ sub search_nav_bot { if ($n < $total) { my $qs = $q->qs_html(o => $n); - $rv .= qq{, next} + $rv .= qq{, next} } if ($o > 0) { $rv .= $n < $total ? '/' : ', '; my $p = $o - $LIM; my $qs = $q->qs_html(o => ($p > 0 ? $p : 0)); - $rv .= qq{prev}; + $rv .= qq{prev}; } $rv; } @@ -140,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 = $_; @@ -150,30 +151,31 @@ sub tdump { $m; } ($mset->items); - require PublicInbox::Thread; + my @rootset; my $th = PublicInbox::Thread->new(@m); - { - no warnings 'once'; - $Mail::Thread::nosubject = 0; - } $th->thread; - if ($q->{r}) { + if ($q->{r}) { # order by relevance $th->order(sub { sort { (eval { $pct{$b->topmost->messageid} } || 0) <=> (eval { $pct{$a->topmost->messageid} } || 0) } @_; }); - } else { - no warnings 'once'; - $th->order(*PublicInbox::View::rsort_ts); + } else { # order by time (default for threaded view) + $th->order(*PublicInbox::View::sort_ts); } - + @rootset = $th->rootset; 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, + fh => $fh, + }; $ctx->{searchview} = 1; - tdump_ent($fh, $git, $state, $_, 0) for $th->rootset; - Email::Address->purge_cache; + tdump_ent($git, $state, $_, 0) for @rootset; + PublicInbox::View::thread_adj_level($state, 0); $fh->write(search_nav_bot($mset, $q). "\n\n" . foot($ctx). '