-sub tdump {
- my ($cb, $res, $mset, $q, $ctx) = @_;
- my $fh = $cb->([200, ['Content-Type'=>'text/html; charset=UTF-8']]);
- $fh->write($res .= '</pre>');
- my %pct;
- my @m = map {
- my $i = $_;
- my $m = PublicInbox::SearchMsg->load_doc($i->get_document);
- $pct{$m->mid} = $i->get_percent;
- $m = $m->mini_mime;
- $m;
- } ($mset->items);
-
- 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)
- } @_;
- });
- } else { # order by time (default for threaded view)
- $th->order(*PublicInbox::View::sort_ts);
- }
- my $skel = '';
- my $state = {
- -inbox => $ctx->{-inbox},
- anchor_idx => 1,
- ctx => $ctx,
- cur_level => 0,
- dst => \$skel,
- fh => $fh,
- mapping => {},
- pct => \%pct,
- prev_attr => '',
- prev_level => 0,
- seen => {},
- srch => $ctx->{srch},
- upfx => './',
- };
- $ctx->{searchview} = 1;
- PublicInbox::View::walk_thread($th, $state,
- *PublicInbox::View::pre_thread);
+sub sort_relevance {
+ [ sort {
+ (eval { $b->topmost->{smsg}->{pct} } // 0) <=>
+ (eval { $a->topmost->{smsg}->{pct} } // 0)
+ } @{$_[0]} ]
+}
+
+sub get_pct ($) {
+ # Capped at "99%" since "100%" takes an extra column in the
+ # thread skeleton view. <xapian/mset.h> says the value isn't
+ # very meaningful, anyways.
+ my $n = $_[0]->get_percent;
+ $n > 99 ? 99 : $n;
+}