]> Sergey Matveev's repositories - public-inbox.git/blobdiff - lib/PublicInbox/Search.pm
doc: re-add missing 1.6 release notes
[public-inbox.git] / lib / PublicInbox / Search.pm
index 58653c9e8fc41f590bac28b4b0814756ff3960e3..7c6a16bec9a1fa87e57c304cf2b1c7a4d635cec0 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 xap_terms);
 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;
@@ -376,7 +376,7 @@ sub qparse_new ($) {
 
        # for IMAP, undocumented for WWW and may be split off go away
        $cb->($qp, $NVRP->new(BYTES, 'bytes:'));
-       $cb->($qp, $NVRP->new(TS, 'ts:'));
+       $cb->($qp, $NVRP->new(TS, 'rt:'));
        $cb->($qp, $NVRP->new(UID, 'uid:'));
 
        while (my ($name, $prefix) = each %bool_pfx_external) {
@@ -424,4 +424,30 @@ 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;
+}
+
+sub xap_terms ($$;@) {
+       my ($pfx, $xdb_or_doc, @docid) = @_; # @docid may be empty ()
+       my %ret;
+       eval {
+               my $end = $xdb_or_doc->termlist_end(@docid);
+               my $cur = $xdb_or_doc->termlist_begin(@docid);
+               for (; $cur != $end; $cur++) {
+                       $cur->skip_to($pfx);
+                       last if $cur == $end;
+                       my $tn = $cur->get_termname;
+                       if (index($tn, $pfx) == 0) {
+                               $ret{substr($tn, length($pfx))} = undef;
+                       }
+               }
+       };
+       \%ret;
+}
+
 1;