]> Sergey Matveev's repositories - public-inbox.git/blobdiff - lib/PublicInbox/Search.pm
miscsearch: index UIDVALIDITY, use as startup cache
[public-inbox.git] / lib / PublicInbox / Search.pm
index 7785d48317ac9c9038d9e4ce33a3443b85179a31..05c679c9a6b3f4386c55d1e52411bc6a985f4002 100644 (file)
@@ -6,7 +6,7 @@
 package PublicInbox::Search;
 use strict;
 use parent qw(Exporter);
-our @EXPORT_OK = qw(retry_reopen);
+our @EXPORT_OK = qw(retry_reopen int_val);
 use List::Util qw(max);
 
 # values for searching, changing the numeric value breaks
@@ -91,6 +91,7 @@ sub load_xapian () {
                                1 : Search::Xapian::ENQ_ASCENDING();
 
                *sortable_serialise = $x.'::sortable_serialise';
+               *sortable_unserialise = $x.'::sortable_unserialise';
                # n.b. FLAG_PURE_NOT is expensive not suitable for a public
                # website as it could become a denial-of-service vector
                # FLAG_PHRASE also seems to cause performance problems chert
@@ -197,8 +198,7 @@ sub xdb_sharded {
 
        # We need numeric sorting so shard[0] is first for reading
        # Xapian metadata, if needed
-       my $last = max(grep(/\A[0-9]+\z/, readdir($dh)));
-       return if !defined($last);
+       my $last = max(grep(/\A[0-9]+\z/, readdir($dh))) // return;
        my (@xdb, $slow_phrase);
        for (0..$last) {
                my $shard_dir = "$self->{xpfx}/$_";
@@ -396,6 +396,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(UID, 'uid:'));
 
        while (my ($name, $prefix) = each %bool_pfx_external) {
                $qp->add_boolean_prefix($name, $_) foreach split(/ /, $prefix);
@@ -436,4 +437,10 @@ sub help {
        \@ret;
 }
 
+sub int_val ($$) {
+       my ($doc, $col) = @_;
+       my $val = $doc->get_value($col) or return; # undefined is '' in Xapian
+       sortable_unserialise($val) + 0; # PV => IV conversion
+}
+
 1;