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 max);
7 use PublicInbox::TestCommon;
9 use PublicInbox::InboxWritable;
10 require_mods(qw(DBD::SQLite Search::Xapian));
11 require PublicInbox::ExtSearchIdx;
13 require_ok 'PublicInbox::LeiXSearch';
14 my ($home, $for_destroy) = tmpdir();
18 push @ibx, create_inbox("v$V-$i", indexlevel => 'full',
22 my $eml = PublicInbox::Eml->new(<<EOM);
24 To: $ibx->{-primary_address}
25 Date: Fri, 02 Oct 1993 0$V:0$i:0$j +0000
26 Subject: v${V}i${i}j$j
27 Message-ID: <v${V}i${i}j$j\@example>
31 $im->add($eml) or BAIL_OUT '->add';
36 my $first = shift @ibx; is($first->{name}, 'v1-3', 'first plucked');
37 my $last = pop @ibx; is($last->{name}, 'v2-6', 'last plucked');
38 my $eidx = PublicInbox::ExtSearchIdx->new("$home/eidx");
39 $eidx->attach_inbox($first);
40 $eidx->attach_inbox($last);
41 $eidx->eidx_sync({fsync => 0});
42 my $es = PublicInbox::ExtSearch->new("$home/eidx");
43 my $lxs = PublicInbox::LeiXSearch->new;
44 for my $ibxish (shuffle($es, @ibx)) {
45 $lxs->prepare_external($ibxish);
47 for my $loc ($lxs->locals) {
48 $lxs->attach_external($loc);
50 my $nr = $lxs->xdb->get_doccount;
51 my $mset = $lxs->mset('d:19931002..19931003', { limit => $nr });
52 is($mset->size, $nr, 'got all messages');
54 for my $mi ($mset->items) {
55 if (my $smsg = $lxs->smsg_for($mi)) {
58 diag "E: ${\$mi->get_docid} missing";
61 is(scalar(@msgs), $nr, 'smsgs retrieved for all');
63 $mset = $lxs->recent(undef, { limit => 1 });
64 is($mset->size, 1, 'one result');
65 my $max = max(map { $_->{docid} } @msgs);
66 is($lxs->smsg_for(($mset->items)[0])->{docid}, $max,
69 my @ibxish = $lxs->locals;
70 is(scalar(@ibxish), scalar(@ibx) + 1, 'got locals back');
71 is($lxs->search, $lxs, '->search works');
72 is($lxs->over, undef, '->over fails');
75 $lxs = PublicInbox::LeiXSearch->new;
76 my $v2ibx = PublicInbox::InboxWritable->new({
77 inboxdir => "$home/v2full",
81 -primary_address => 'v2full@example.com',
83 my $im = $v2ibx->importer(0);
84 $im->add(eml_load('t/plack-qp.eml'));
86 my $v1ibx = PublicInbox::InboxWritable->new({
87 inboxdir => "$home/v1medium",
90 indexlevel => 'medium',
91 -primary_address => 'v1medium@example.com',
93 $im = $v1ibx->importer(0);
94 $im->add(eml_load('t/utf8.eml'));
96 $lxs->prepare_external($v1ibx);
97 $lxs->prepare_external($v2ibx);
98 for my $loc ($lxs->locals) {
99 $lxs->attach_external($loc);
101 my $mset = $lxs->mset('m:testmessage@example.com');
102 is($mset->size, 1, 'got m: match on medium+full XSearch mix');