]> Sergey Matveev's repositories - public-inbox.git/commitdiff
searchview: save a column in &x=t thread skeleton
authorEric Wong <e@80x24.org>
Fri, 20 Dec 2019 06:58:27 +0000 (06:58 +0000)
committerEric Wong <e@80x24.org>
Sat, 21 Dec 2019 05:42:44 +0000 (05:42 +0000)
Displaying "100%" wastes a precious column.  Show "99%" instead
since there's little practical difference and <xapian/mset.h>
states:

  Note that these generally aren't percentages of anything meaningful
  (unless you use a custom weighting formula where they are!)

And we're not using a custom weighting formula.

lib/PublicInbox/SearchView.pm
lib/PublicInbox/View.pm

index 566808e10a9c66f2e57267d54772c88f359b63f4..7afb07540f7b8d6cab41769bd2becc2835b35cef 100644 (file)
@@ -113,7 +113,7 @@ sub mset_summary {
        my $obfs_ibx = $ibx->{obfuscate} ? $ibx : undef;
        foreach my $m ($mset->items) {
                my $rank = sprintf("%${pad}d", $m->get_rank + 1);
-               my $pct = $m->get_percent;
+               my $pct = get_pct($m);
                my $smsg = load_doc_retry($srch, $m);
                unless ($smsg) {
                        eval {
@@ -264,6 +264,14 @@ sub sort_relevance {
        } @{$_[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;
+}
+
 sub mset_thread {
        my ($ctx, $mset, $q) = @_;
        my %pct;
@@ -271,7 +279,7 @@ sub mset_thread {
        my $msgs = $ibx->search->retry_reopen(sub { [ map {
                my $i = $_;
                my $smsg = PublicInbox::SearchMsg->load_doc($i->get_document);
-               $pct{$smsg->mid} = $i->get_percent;
+               $pct{$smsg->mid} = get_pct($i);
                $smsg;
        } ($mset->items) ]});
        my $r = $q->{r};
index 5924a2a727f2baacadb1c38a35ca813e45ca4ec4..0b1026387f18c815f6bec6200fdc9f353e1f3922 100644 (file)
@@ -955,10 +955,10 @@ sub skel_dump {
        if (my $pct = $ctx->{pct}) {
                $pct = $pct->{$smsg->{mid}};
                if (defined $pct) {
-                       $d .= (sprintf(' % 3u', $pct) . '%');
+                       $d .= (sprintf(' % 2u', $pct) . '%');
                } else {
                        $unmatched = 1;
-                       $d .= '     ';
+                       $d .= '    ';
                }
        }
        $d .= ' ' . indent_for($level) . th_pfx($level);
@@ -1022,7 +1022,7 @@ sub _skel_ghost {
 
        my $mid = $node->{id};
        my $d = '     [not found] ';
-       $d .= '     '  if exists $ctx->{pct};
+       $d .= '    '  if exists $ctx->{pct};
        $d .= indent_for($level) . th_pfx($level);
        my $upfx = $ctx->{-upfx};
        my $m = PublicInbox::Hval->new_msgid($mid);