my $srch = $self->{search} ||= eval {
_cleanup_later($self);
require PublicInbox::Search;
- PublicInbox::Search->new($self, $self->{altid});
+ PublicInbox::Search->new($self);
};
($over_only || eval { $srch->xdb }) ? $srch : undef;
}
}
sub new {
- my ($class, $mainrepo, $altid) = @_;
- my $version = 1;
- my $ibx = $mainrepo;
- if (ref $ibx) {
- $version = $ibx->{version} || 1;
- $mainrepo = $ibx->{mainrepo};
- }
+ my ($class, $ibx) = @_;
+ ref $ibx or die "BUG: expected PublicInbox::Inbox object: $ibx";
my $self = bless {
- mainrepo => $mainrepo,
- altid => $altid,
- version => $version,
+ mainrepo => $ibx->{mainrepo},
+ altid => $ibx->{altid},
+ version => $ibx->{version} // 1,
}, $class;
my $dir = xdir($self, 1);
$self->{over_ro} = PublicInbox::Over->new("$dir/over.sqlite3");
my $git_dir = "$tmpdir/a.git";
my $alt_file = "$tmpdir/another-nntp.sqlite3";
my $altid = [ "serial:gmane:file=$alt_file" ];
+my $ibx;
{
my $mm = PublicInbox::Msgmap->new_file($alt_file, 1);
$im->done;
}
{
- my $ibx = PublicInbox::Inbox->new({mainrepo => $git_dir});
+ $ibx = PublicInbox::Inbox->new({mainrepo => $git_dir});
$ibx->{altid} = $altid;
my $rw = PublicInbox::SearchIdx->new($ibx, 1);
$rw->index_sync;
}
{
- my $ro = PublicInbox::Search->new($git_dir, $altid);
+ my $ro = PublicInbox::Search->new($ibx);
my $msgs = $ro->query("gmane:1234");
is_deeply([map { $_->mid } @$msgs], ['a@example.com'], 'got one match');
my ($root_id, $last_id);
is(0, system(qw(git init --shared -q --bare), $git_dir), "git init (main)");
-eval { PublicInbox::Search->new($git_dir)->xdb };
+eval { PublicInbox::Search->new($ibx)->xdb };
ok($@, "exception raised on non-existent DB");
my $rw = PublicInbox::SearchIdx->new($ibx, 1);
$rw->_xdb_release;
});
$rw = undef;
-my $ro = PublicInbox::Search->new($git_dir);
+my $ro = PublicInbox::Search->new($ibx);
my $rw_commit = sub {
$rw->commit_txn_lazy if $rw;
$rw = PublicInbox::SearchIdx->new($ibx, 1);