]> Sergey Matveev's repositories - public-inbox.git/blobdiff - lib/PublicInbox/Search.pm
lei query + pagination sorta working
[public-inbox.git] / lib / PublicInbox / Search.pm
index 58653c9e8fc41f590bac28b4b0814756ff3960e3..7f68ee0122a8d5754d845ba97ee3559cd4600bfb 100644 (file)
@@ -1,4 +1,4 @@
-# Copyright (C) 2015-2020 all contributors <meta@public-inbox.org>
+# Copyright (C) 2015-2021 all contributors <meta@public-inbox.org>
 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
 # based on notmuch, but with no concept of folders, files or flags
 #
@@ -6,7 +6,7 @@
 package PublicInbox::Search;
 use strict;
 use parent qw(Exporter);
-our @EXPORT_OK = qw(retry_reopen int_val);
+our @EXPORT_OK = qw(retry_reopen int_val get_pct);
 use List::Util qw(max);
 
 # values for searching, changing the numeric value breaks
@@ -196,6 +196,7 @@ sub xdb_shards_flat ($) {
        my $xpfx = $self->{xpfx};
        my (@xdb, $slow_phrase);
        load_xapian();
+       $self->{qp_flags} //= $QP_FLAGS;
        if ($xpfx =~ m/xapian${\SCHEMA_VERSION}\z/) {
                @xdb = ($X{Database}->new($xpfx));
                $self->{qp_flags} |= FLAG_PHRASE() if !-f "$xpfx/iamchert";
@@ -232,7 +233,6 @@ sub mset_to_artnums {
 sub xdb ($) {
        my ($self) = @_;
        $self->{xdb} //= do {
-               $self->{qp_flags} //= $QP_FLAGS;
                my @xdb = $self->xdb_shards_flat or return;
                $self->{nshard} = scalar(@xdb);
                my $xdb = shift @xdb;
@@ -424,4 +424,12 @@ sub int_val ($$) {
        sortable_unserialise($val) + 0; # PV => IV conversion
 }
 
+sub get_pct ($) { # mset item
+       # 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;
+}
+
 1;