X-Git-Url: http://www.git.stargrave.org/?a=blobdiff_plain;f=lib%2FPublicInbox%2FSearchView.pm;h=4fbf59ef2ca080d22db624c393d0db1dcc9084d6;hb=87678710135973f72722258e171fc00f85c86ec8;hp=6587d37fb9f94011e955ada6cb6139172cddd398;hpb=65e3cc8f6cc73e45db827cbeee4ccecbf1502496;p=public-inbox.git diff --git a/lib/PublicInbox/SearchView.pm b/lib/PublicInbox/SearchView.pm index 6587d37f..4fbf59ef 100644 --- a/lib/PublicInbox/SearchView.pm +++ b/lib/PublicInbox/SearchView.pm @@ -1,4 +1,4 @@ -# Copyright (C) 2015-2019 all contributors +# Copyright (C) 2015-2020 all contributors # License: AGPL-3.0+ # # Displays search results for the web interface @@ -6,18 +6,15 @@ package PublicInbox::SearchView; use strict; use warnings; use URI::Escape qw(uri_unescape uri_escape); -use PublicInbox::SearchMsg; -use PublicInbox::Hval qw/ascii_html obfuscate_addrs/; +use PublicInbox::Smsg; +use PublicInbox::Hval qw(ascii_html obfuscate_addrs mid_href); use PublicInbox::View; use PublicInbox::WwwAtomStream; -use PublicInbox::MID qw(MID_ESC); -use PublicInbox::MIME; -require PublicInbox::Git; -require PublicInbox::SearchThread; +use PublicInbox::SearchThread; our $LIM = 200; my %rmap_inc; -sub noop {} +my $noop = sub {}; sub mbox_results { my ($ctx) = @_; @@ -62,7 +59,7 @@ retry: if ($err) { $code = 400; $ctx->{-html_tip} = '
'.err_txt($ctx, $err).'

'; - $cb = *noop; + $cb = $noop; } elsif ($total == 0) { if (defined($ctx->{-uxs_retried})) { # undo retry damage: @@ -74,7 +71,7 @@ retry: } $code = 404; $ctx->{-html_tip} = "
\n[No results found]

"; - $cb = *noop; + $cb = $noop; } else { return adump($_[0], $mset, $q, $ctx) if $x eq 'A'; @@ -103,7 +100,7 @@ sub mset_summary { foreach my $m ($mset->items) { my $rank = sprintf("%${pad}d", $m->get_rank + 1); my $pct = get_pct($m); - my $smsg = PublicInbox::SearchMsg::from_mitem($m, $srch); + my $smsg = PublicInbox::Smsg::from_mitem($m, $srch); unless ($smsg) { eval { $m = "$m ".$m->get_docid . " expired\n"; @@ -111,21 +108,21 @@ sub mset_summary { }; next; } - my $s = ascii_html($smsg->subject); - my $f = ascii_html($smsg->from_name); + my $s = ascii_html($smsg->{subject}); + my $f = ascii_html($smsg->{from_name}); if ($obfs_ibx) { obfuscate_addrs($obfs_ibx, $s); obfuscate_addrs($obfs_ibx, $f); } - my $date = PublicInbox::View::fmt_ts($smsg->ds); - my $mid = PublicInbox::Hval->new_msgid($smsg->mid)->{href}; + my $date = PublicInbox::View::fmt_ts($smsg->{ds}); + my $mid = mid_href($smsg->{mid}); $s = '(no subject)' if $s eq ''; $$res .= qq{$rank. }. $s . "\n"; $$res .= "$pfx - by $f @ $date UTC [$pct%]\n\n"; } $$res .= search_nav_bot($mset, $q); - *noop; + $noop; } # shorten "/full/path/to/Foo/Bar.pm" to "Foo/Bar.pm" so error @@ -263,7 +260,7 @@ sub load_msgs { my ($mset) = @_; [ map { my $mi = $_; - my $smsg = PublicInbox::SearchMsg::from_mitem($mi); + my $smsg = PublicInbox::Smsg::from_mitem($mi); $smsg->{pct} = get_pct($mi); $smsg; } ($mset->items) ] @@ -271,7 +268,8 @@ sub load_msgs { sub mset_thread { my ($ctx, $mset, $q) = @_; - my $msgs = $ctx->{-inbox}->search->retry_reopen(\&load_msgs, $mset); + my $ibx = $ctx->{-inbox}; + my $msgs = $ibx->search->retry_reopen(\&load_msgs, $mset); my $r = $q->{r}; my $rootset = PublicInbox::SearchThread::thread($msgs, $r ? \&sort_relevance : \&PublicInbox::View::sort_ds, @@ -280,7 +278,7 @@ sub mset_thread { $ctx->{-upfx} = ''; $ctx->{anchor_idx} = 1; $ctx->{cur_level} = 0; - $ctx->{dst} = \$skel; + $ctx->{skel} = \$skel; $ctx->{mapping} = {}; $ctx->{searchview} = 1; $ctx->{prev_attr} = ''; @@ -288,9 +286,9 @@ sub mset_thread { $ctx->{s_nr} = scalar(@$msgs).'+ results'; # reduce hash lookups in skel_dump - $ctx->{-obfuscate} = $ctx->{-inbox}->{obfuscate}; + $ctx->{-obfs_ibx} = $ibx->{obfuscate} ? $ibx : undef; PublicInbox::View::walk_thread($rootset, $ctx, - *PublicInbox::View::pre_thread); + \&PublicInbox::View::pre_thread); @$msgs = reverse @$msgs if $r; $ctx->{msgs} = $msgs; @@ -306,7 +304,7 @@ sub mset_thread_i { return PublicInbox::View::index_entry($smsg, $ctx, scalar @$msgs); } - my ($skel) = delete @$ctx{qw(dst msgs)}; + my ($skel) = delete @$ctx{qw(skel msgs)}; $$skel .= "\n"; } @@ -340,7 +338,7 @@ sub adump_i { my ($ctx) = @_; while (my $mi = shift @{$ctx->{items}}) { my $smsg = eval { - PublicInbox::SearchMsg::from_mitem($mi, $ctx->{srch}); + PublicInbox::Smsg::from_mitem($mi, $ctx->{srch}); } or next; $ctx->{-inbox}->smsg_mime($smsg) and return $smsg; } @@ -350,7 +348,6 @@ package PublicInbox::SearchQuery; use strict; use warnings; use URI::Escape qw(uri_escape); -use PublicInbox::Hval; use PublicInbox::MID qw(MID_ESC); sub new { @@ -369,14 +366,10 @@ sub new { } sub qs_html { - my ($self, %over) = @_; + my ($self, %override) = @_; - if (keys %over) { - my $tmp = bless { %$self }, ref($self); - foreach my $k (keys %over) { - $tmp->{$k} = $over{$k}; - } - $self = $tmp; + if (scalar(keys(%override))) { + $self = bless { (%$self, %override) }, ref($self); } my $q = uri_escape($self->{'q'}, MID_ESC);