]> Sergey Matveev's repositories - public-inbox.git/blobdiff - lib/PublicInbox/Search.pm
lei inspect: account for non-extindex inboxes
[public-inbox.git] / lib / PublicInbox / Search.pm
index af0a35d9b599f1c991ba4c59b7c926178793d940..d89bf545739b17b7097ea37a85cb0be1e58e858d 100644 (file)
@@ -199,7 +199,7 @@ sub xdb_shards_flat ($) {
        my (@xdb, $slow_phrase);
        load_xapian();
        $self->{qp_flags} //= $QP_FLAGS;
-       if ($xpfx =~ m/xapian${\SCHEMA_VERSION}\z/) {
+       if ($xpfx =~ m!/xapian[0-9]+\z!) {
                @xdb = ($X{Database}->new($xpfx));
                $self->{qp_flags} |= FLAG_PHRASE() if !-f "$xpfx/iamchert";
        } else {
@@ -234,12 +234,12 @@ sub mset_to_artnums {
 
 sub xdb ($) {
        my ($self) = @_;
-       $self->{xdb} //= do {
+       $self->{xdb} // do {
                my @xdb = $self->xdb_shards_flat or return;
                $self->{nshard} = scalar(@xdb);
                my $xdb = shift @xdb;
                $xdb->add_database($_) for @xdb;
-               $xdb;
+               $self->{xdb} = $xdb;
        };
 }
 
@@ -247,10 +247,10 @@ sub new {
        my ($class, $ibx) = @_;
        ref $ibx or die "BUG: expected PublicInbox::Inbox object: $ibx";
        my $xap = $ibx->version > 1 ? 'xap' : 'public-inbox/xapian';
-       bless {
-               xpfx => "$ibx->{inboxdir}/$xap" . SCHEMA_VERSION,
-               altid => $ibx->{altid},
-       }, $class;
+       my $xpfx = "$ibx->{inboxdir}/$xap".SCHEMA_VERSION;
+       my $self = bless { xpfx => $xpfx }, $class;
+       $self->{altid} = $ibx->{altid} if defined($ibx->{altid});
+       $self;
 }
 
 sub reopen {
@@ -409,7 +409,6 @@ sub retry_reopen {
                # Exception: The revision being read has been discarded -
                # you should call Xapian::Database::reopen()
                if (ref($@) =~ /\bDatabaseModifiedError\b/) {
-                       warn "# reopen try #$i on $@\n";
                        reopen($self);
                } else {
                        # let caller decide how to spew, because ExtMsg queries
@@ -571,4 +570,12 @@ sub xap_terms ($$;@) {
        wantarray ? sort(keys(%ret)) : \%ret;
 }
 
+# get combined docid from over.num:
+# (not generic Xapian, only works with our sharding scheme)
+sub num2docid ($$) {
+       my ($self, $num) = @_;
+       my $nshard = $self->{nshard};
+       ($num - 1) * $nshard + $num % $nshard + 1;
+}
+
 1;