2 # Copyright (C) 2020-2021 all contributors <meta@public-inbox.org>
3 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
6 use List::Util qw(shuffle);
7 use PublicInbox::TestCommon;
9 require_mods(qw(DBD::SQLite Search::Xapian));
10 require PublicInbox::ExtSearchIdx;
12 require_ok 'PublicInbox::LeiXSearch';
13 require_ok 'PublicInbox::LeiALE';
14 require_ok 'PublicInbox::LEI';
15 my ($home, $for_destroy) = tmpdir();
19 push @ibx, create_inbox("v$V-$i", indexlevel => 'full',
23 my $eml = PublicInbox::Eml->new(<<EOM);
25 To: $ibx->{-primary_address}
26 Date: Fri, 02 Oct 1993 0$V:0$i:0$j +0000
27 Subject: v${V}i${i}j$j
28 Message-ID: <v${V}i${i}j$j\@example>
32 $im->add($eml) or BAIL_OUT '->add';
37 my $first = shift @ibx; is($first->{name}, 'v1-3', 'first plucked');
38 my $last = pop @ibx; is($last->{name}, 'v2-6', 'last plucked');
39 my $eidx = PublicInbox::ExtSearchIdx->new("$home/eidx");
40 $eidx->attach_inbox($first);
41 $eidx->attach_inbox($last);
42 $eidx->eidx_sync({fsync => 0});
43 my $es = PublicInbox::ExtSearch->new("$home/eidx");
44 my $lxs = PublicInbox::LeiXSearch->new;
45 for my $ibxish (shuffle($es, @ibx)) {
46 $lxs->prepare_external($ibxish);
48 for my $loc ($lxs->locals) {
49 $lxs->attach_external($loc);
51 my $nr = $lxs->xdb->get_doccount;
52 my $mset = $lxs->mset('d:19931002..19931003', { limit => $nr });
53 is($mset->size, $nr, 'got all messages');
55 for my $mi ($mset->items) {
56 if (my $smsg = $lxs->smsg_for($mi)) {
59 diag "E: ${\$mi->get_docid} missing";
62 is(scalar(@msgs), $nr, 'smsgs retrieved for all');
64 $mset = $lxs->recent(undef, { limit => 1 });
65 is($mset->size, 1, 'one result');
67 my @ibxish = $lxs->locals;
68 is(scalar(@ibxish), scalar(@ibx) + 1, 'got locals back');
69 is($lxs->search, $lxs, '->search works');
70 is($lxs->over, undef, '->over fails');
73 $lxs = PublicInbox::LeiXSearch->new;
74 my $v2ibx = create_inbox 'v2full', version => 2, sub {
75 $_[0]->add(eml_load('t/plack-qp.eml'));
77 my $v1ibx = create_inbox 'v1medium', indexlevel => 'medium',
78 tmpdir => "$home/v1tmp", sub {
79 $_[0]->add(eml_load('t/utf8.eml'));
81 $lxs->prepare_external($v1ibx);
82 $lxs->prepare_external($v2ibx);
83 for my $loc ($lxs->locals) {
84 $lxs->attach_external($loc);
86 my $mset = $lxs->mset('m:testmessage@example.com');
87 is($mset->size, 1, 'got m: match on medium+full XSearch mix');
88 my $mitem = ($mset->items)[0];
89 my $smsg = $lxs->smsg_for($mitem) or BAIL_OUT 'smsg_for broken';
91 my $ale = PublicInbox::LeiALE::_new("$home/ale");
92 my $lei = bless {}, 'PublicInbox::LEI';
93 $ale->refresh_externals($lxs, $lei);
94 my $exp = [ $smsg->{blob}, 'blob', -s 't/utf8.eml' ];
95 is_deeply([ $ale->git->check($smsg->{blob}) ], $exp, 'ale->git->check');
97 $lxs = PublicInbox::LeiXSearch->new;
98 $lxs->prepare_external($v2ibx);
99 $ale->refresh_externals($lxs, $lei);
100 is_deeply([ $ale->git->check($smsg->{blob}) ], $exp,
101 'ale->git->check remembered inactive external');
103 rename("$home/v1tmp", "$home/v1moved") or BAIL_OUT "rename: $!";
104 $ale->refresh_externals($lxs, $lei);
105 is($ale->git->check($smsg->{blob}), undef,
106 'missing after directory gone');