X-Git-Url: http://www.git.stargrave.org/?a=blobdiff_plain;f=lib%2FPublicInbox%2FSearchView.pm;h=9723306943f1d3433a35761cd7cf7b95a22a0436;hb=d4cb7fb06031435cd25f5e000bf9c0e4b8b30177;hp=8cffdedbb33a27dce981fd4d503776de75c1b62d;hpb=9b5bf24a115346ef6095f4c613b4579fde112714;p=public-inbox.git
diff --git a/lib/PublicInbox/SearchView.pm b/lib/PublicInbox/SearchView.pm
index 8cffdedb..97233069 100644
--- a/lib/PublicInbox/SearchView.pm
+++ b/lib/PublicInbox/SearchView.pm
@@ -10,14 +10,11 @@ use PublicInbox::SearchMsg;
use PublicInbox::Hval qw/ascii_html obfuscate_addrs/;
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';
@@ -88,17 +85,6 @@ retry:
PublicInbox::WwwStream->response($ctx, $code, $cb);
}
-# allow undef for individual doc loads...
-sub load_doc_retry {
- my ($srch, $mitem) = @_;
-
- eval {
- $srch->retry_reopen(sub {
- PublicInbox::SearchMsg->load_doc($mitem->get_document)
- });
- }
-}
-
# display non-nested search results similar to what users expect from
# regular WWW search engines:
sub mset_summary {
@@ -114,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 = load_doc_retry($srch, $m);
+ my $smsg = PublicInbox::SearchMsg::from_mitem($m, $srch);
unless ($smsg) {
eval {
$m = "$m ".$m->get_docid . " expired\n";
@@ -136,7 +122,7 @@ sub mset_summary {
$$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
@@ -270,14 +256,19 @@ sub get_pct ($) {
$n > 99 ? 99 : $n;
}
+sub load_msgs {
+ my ($mset) = @_;
+ [ map {
+ my $mi = $_;
+ my $smsg = PublicInbox::SearchMsg::from_mitem($mi);
+ $smsg->{pct} = get_pct($mi);
+ $smsg;
+ } ($mset->items) ]
+}
+
sub mset_thread {
my ($ctx, $mset, $q) = @_;
- my $msgs = $ctx->{-inbox}->search->retry_reopen(sub { [ map {
- my $i = $_;
- my $smsg = PublicInbox::SearchMsg->load_doc($i->get_document);
- $smsg->{pct} = get_pct($i);
- $smsg;
- } ($mset->items) ]});
+ my $msgs = $ctx->{-inbox}->search->retry_reopen(\&load_msgs, $mset);
my $r = $q->{r};
my $rootset = PublicInbox::SearchThread::thread($msgs,
$r ? \&sort_relevance : \&PublicInbox::View::sort_ds,
@@ -286,7 +277,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} = '';
@@ -296,7 +287,7 @@ sub mset_thread {
# reduce hash lookups in skel_dump
$ctx->{-obfuscate} = $ctx->{-inbox}->{obfuscate};
PublicInbox::View::walk_thread($rootset, $ctx,
- *PublicInbox::View::pre_thread);
+ \&PublicInbox::View::pre_thread);
@$msgs = reverse @$msgs if $r;
$ctx->{msgs} = $msgs;
@@ -312,7 +303,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";
}
@@ -345,7 +336,9 @@ sub adump {
sub adump_i {
my ($ctx) = @_;
while (my $mi = shift @{$ctx->{items}}) {
- my $smsg = load_doc_retry($ctx->{srch}, $mi) or next;
+ my $smsg = eval {
+ PublicInbox::SearchMsg::from_mitem($mi, $ctx->{srch});
+ } or next;
$ctx->{-inbox}->smsg_mime($smsg) and return $smsg;
}
}
@@ -354,7 +347,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 {