use PublicInbox::SearchMsg;
use PublicInbox::Hval qw/ascii_html/;
use PublicInbox::View;
-use PublicInbox::MID qw(mid2path mid_clean mid_mime);
+use PublicInbox::MID qw(mid2path mid_mime);
use Email::MIME;
require PublicInbox::Git;
+require PublicInbox::Thread;
our $LIM = 50;
sub sres_top_html {
my ($ctx) = @_;
- my $q = PublicInbox::SearchQuery->new($ctx->{cgi});
+ my $q = PublicInbox::SearchQuery->new($ctx->{qp});
my $code = 200;
# double the limit for expanded views:
if ($n < $total) {
my $qs = $q->qs_html(o => $n);
- $rv .= qq{, <a\nhref="?$qs">next</a>}
+ $rv .= qq{, <a\nhref="?$qs"\nrel=next>next</a>}
}
if ($o > 0) {
$rv .= $n < $total ? '/' : ', ';
my $p = $o - $LIM;
my $qs = $q->qs_html(o => ($p > 0 ? $p : 0));
- $rv .= qq{<a\nhref="?$qs">prev</a>};
+ $rv .= qq{<a\nhref="?$qs"\nrel=prev>prev</a>};
}
$rv;
}
$m;
} ($mset->items);
- my @rootset;
- my $th = PublicInbox::View::thread_results(\@m, 0, $q->{r});
- if ($q->{r}) {
+ my $th = PublicInbox::Thread->new(@m);
+ $th->thread;
+ if ($q->{r}) { # order by relevance
$th->order(sub {
sort { (eval { $pct{$b->topmost->messageid} } || 0)
<=>
(eval { $pct{$a->topmost->messageid} } || 0)
} @_;
});
- @rootset = $th->rootset;
- } else {
- @rootset = sort {
- (eval { $b->topmost->message->header('X-PI-TS') } || 0)
- <=>
- (eval { $a->topmost->message->header('X-PI-TS') } || 0)
- } $th->rootset;
+ } else { # order by time (default for threaded view)
+ $th->order(*PublicInbox::View::sort_ts);
}
-
- my $git = $ctx->{git} ||= PublicInbox::Git->new($ctx->{git_dir});
my $state = {
ctx => $ctx,
anchor_idx => 0,
pct => \%pct,
cur_level => 0,
+ -inbox => $ctx->{-inbox},
fh => $fh,
};
$ctx->{searchview} = 1;
- tdump_ent($git, $state, $_, 0) for @rootset;
+ PublicInbox::View::walk_thread($th, $state, *tdump_ent);
PublicInbox::View::thread_adj_level($state, 0);
- Email::Address->purge_cache;
$fh->write(search_nav_bot($mset, $q). "\n\n" .
foot($ctx). '</pre></body></html>');
}
sub tdump_ent {
- my ($git, $state, $node, $level) = @_;
- return unless $node;
+ my ($state, $level, $node) = @_;
my $mime = $node->message;
if ($mime) {
# lazy load the full message from mini_mime:
my $mid = mid_mime($mime);
- $mime = eval {
- my $path = mid2path(mid_clean($mid));
- Email::MIME->new($git->cat_file('HEAD:'.$path));
- };
+ $mime = eval { $state->{-inbox}->msg_by_mid($mid) } and
+ $mime = Email::MIME->new($mime);
}
if ($mime) {
my $end = PublicInbox::View::thread_adj_level($state, $level);
my $mid = $node->messageid;
PublicInbox::View::ghost_flush($state, '', $mid, $level);
}
- tdump_ent($git, $state, $node->child, $level + 1);
- tdump_ent($git, $state, $node->next, $level);
}
sub foot {
sub adump {
my ($cb, $mset, $q, $ctx) = @_;
my $fh = $cb->([ 200, ['Content-Type' => 'application/atom+xml']]);
- my $git = $ctx->{git} ||= PublicInbox::Git->new($ctx->{git_dir});
+ my $ibx = $ctx->{-inbox};
my $feed_opts = PublicInbox::Feed::get_feedopts($ctx);
my $x = ascii_html($q->{'q'});
$x = qq{$x - search results};
for ($mset->items) {
$x = PublicInbox::SearchMsg->load_doc($_->get_document)->mid;
$x = mid2path($x);
- PublicInbox::Feed::add_to_feed($feed_opts, $fh, $x, $git);
+ my $s = PublicInbox::Feed::feed_entry($feed_opts, $x, $ibx);
+ $fh->write($s) if defined $s;
}
PublicInbox::Feed::end_feed($fh);
}
use PublicInbox::Hval;
sub new {
- my ($class, $cgi) = @_;
- my $r = $cgi->param('r');
+ my ($class, $qp) = @_;
+
+ my $r = $qp->{r};
bless {
- q => $cgi->param('q'),
- x => $cgi->param('x') || '',
- o => int($cgi->param('o') || 0) || 0,
+ q => $qp->{'q'},
+ x => $qp->{x} || '',
+ o => (($qp->{o} || '0') =~ /(\d+)/),
r => (defined $r && $r ne '0'),
}, $class;
}