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>
7 use List::Util qw(shuffle max);
8 use PublicInbox::TestCommon;
9 use PublicInbox::ExtSearchIdx;
11 use PublicInbox::InboxWritable;
12 require_mods(qw(DBD::SQLite Search::Xapian));
14 require_ok 'PublicInbox::LeiXSearch';
15 my ($home, $for_destroy) = tmpdir();
19 my $ibx = PublicInbox::InboxWritable->new({
20 inboxdir => "$home/v$V-$i",
21 name => "test-v$V-$i",
23 indexlevel => 'medium',
24 -primary_address => "v$V-$i\@example.com",
25 }, { nproc => int(rand(8)) + 1 });
27 my $im = $ibx->importer(0);
29 my $eml = PublicInbox::Eml->new(<<EOF);
31 To: $ibx->{-primary_address}
32 Date: Fri, 02 Oct 1993 0$V:0$i:0$j +0000
33 Subject: v${V}i${i}j$j
34 Message-ID: <v${V}i${i}j$j\@example>
43 my $first = shift @ibx; is($first->{name}, 'test-v1-3', 'first plucked');
44 my $last = pop @ibx; is($last->{name}, 'test-v2-6', 'last plucked');
45 my $eidx = PublicInbox::ExtSearchIdx->new("$home/eidx");
46 $eidx->attach_inbox($first);
47 $eidx->attach_inbox($last);
48 $eidx->eidx_sync({fsync => 0});
49 my $es = PublicInbox::ExtSearch->new("$home/eidx");
50 my $lxs = PublicInbox::LeiXSearch->new;
51 for my $ibxish (shuffle($es, @ibx)) {
52 $lxs->attach_external($ibxish);
54 my $nr = $lxs->xdb->get_doccount;
55 my $mset = $lxs->mset('d:19931002..19931003', { limit => $nr });
56 is($mset->size, $nr, 'got all messages');
58 for my $mi ($mset->items) {
59 if (my $smsg = $lxs->smsg_for($mi)) {
62 diag "E: ${\$mi->get_docid} missing";
65 is(scalar(@msgs), $nr, 'smsgs retrieved for all');
67 $mset = $lxs->recent(undef, { limit => 1 });
68 is($mset->size, 1, 'one result');
69 my $max = max(map { $_->{docid} } @msgs);
70 is($lxs->smsg_for(($mset->items)[0])->{docid}, $max,