X-Git-Url: http://www.git.stargrave.org/?a=blobdiff_plain;f=lib%2FPublicInbox%2FSearchView.pm;h=a5974034d20a3335ddc517e50d7b9c3e181b4b98;hb=1a8eb0a43c68e64b77fdd3c4ebd977a1ab88e71b;hp=5a95a055eb3230c7cfd49db1317b0cfa11f5c9f9;hpb=09e5f81e8259e7deffe0973b3547a5c77fbf3fc5;p=public-inbox.git diff --git a/lib/PublicInbox/SearchView.pm b/lib/PublicInbox/SearchView.pm index 5a95a055..a5974034 100644 --- a/lib/PublicInbox/SearchView.pm +++ b/lib/PublicInbox/SearchView.pm @@ -5,15 +5,16 @@ package PublicInbox::SearchView; use strict; use warnings; +use URI::Escape qw(uri_unescape uri_escape); use PublicInbox::SearchMsg; -use PublicInbox::Hval qw/ascii_html/; +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); +use PublicInbox::MID qw(mid2path mid_mime mid_clean mid_escape MID_ESC); use PublicInbox::MIME; require PublicInbox::Git; require PublicInbox::SearchThread; -our $LIM = 50; +our $LIM = 200; sub noop {} @@ -29,19 +30,27 @@ sub sres_top_html { mset => 1, relevance => $q->{r}, }; - my ($mset, $total); + my ($mset, $total, $err, $cb); +retry: eval { $mset = $ctx->{srch}->query($q->{'q'}, $opts); $total = $mset->get_matches_estimated; }; - my $err = $@; + $err = $@; ctx_prepare($q, $ctx); - my $cb; if ($err) { $code = 400; $ctx->{-html_tip} = '
'.err_txt($ctx, $err).'
\n[No results found]
Search results ordered by ["; + my $rv = ''; + my $initial_q = $ctx->{-uxs_retried}; + if (defined $initial_q) { + my $rewritten = $q->{'q'}; + utf8::decode($initial_q); + utf8::decode($rewritten); + $initial_q = ascii_html($initial_q); + $rewritten = ascii_html($rewritten); + $rv .= " Warning: Initial query:\n $initial_q\n"; + $rv .= " returned no results, used:\n"; + $rv .= " $rewritten\n instead\n\n"; + } + + $rv .= 'Search results ordered by ['; if ($q->{r}) { my $d = $q->qs_html(r => 0); $rv .= qq{date|relevance}; @@ -145,7 +173,7 @@ sub search_nav_bot { my $o = $q->{o}; my $end = $o + $nr; my $beg = $o + 1; - my $rv = ''; + my $rv = ''; if ($beg <= $end) { $rv .= "Results $beg-$end of $total"; $rv .= ' (estimated)' if $end != $total; @@ -185,9 +213,9 @@ sub mset_thread { $pct{$smsg->mid} = $i->get_percent; $smsg; } ($mset->items) ]}); - + my $r = $q->{r}; my $rootset = PublicInbox::SearchThread::thread($msgs, - $q->{r} ? sort_relevance(\%pct) : *PublicInbox::View::sort_ts); + $r ? sort_relevance(\%pct) : *PublicInbox::View::sort_ts); my $skel = search_nav_bot($mset, $q). ""; my $inbox = $ctx->{-inbox}; $ctx->{-upfx} = ''; @@ -201,13 +229,16 @@ sub mset_thread { $ctx->{seen} = {}; $ctx->{s_nr} = scalar(@$msgs).'+ results'; + # reduce hash lookups in skel_dump + $ctx->{-obfuscate} = $ctx->{-inbox}->{obfuscate}; PublicInbox::View::walk_thread($rootset, $ctx, *PublicInbox::View::pre_thread); + @$msgs = reverse @$msgs if $r; my $mime; sub { return unless $msgs; - while ($mime = shift @$msgs) { + while ($mime = pop @$msgs) { $mime = $inbox->msg_by_smsg($mime) and last; } if ($mime) { @@ -222,7 +253,9 @@ sub mset_thread { sub ctx_prepare { my ($q, $ctx) = @_; - my $qh = ascii_html($q->{'q'}); + my $qh = $q->{'q'}; + utf8::decode($qh); + $qh = ascii_html($qh); $ctx->{-q_value_html} = $qh; $ctx->{-atom} = '?'.$q->qs_html(x => 'A', r => undef); $ctx->{-title_html} = "$qh - search results"; @@ -254,8 +287,9 @@ sub adump { package PublicInbox::SearchQuery; use strict; use warnings; +use URI::Escape qw(uri_escape); use PublicInbox::Hval; -use PublicInbox::MID qw(mid_escape); +use PublicInbox::MID qw(MID_ESC); sub new { my ($class, $qp) = @_; @@ -280,7 +314,7 @@ sub qs_html { $self = $tmp; } - my $q = mid_escape($self->{'q'}); + my $q = uri_escape($self->{'q'}, MID_ESC); $q =~ s/%20/+/g; # improve URL readability my $qs = "q=$q";