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 require_mods(qw(DBD::SQLite Search::Xapian));
10 require PublicInbox::ExtSearchIdx;
12 require_ok 'PublicInbox::LeiXSearch';
13 my ($home, $for_destroy) = tmpdir();
17 push @ibx, create_inbox("v$V-$i", indexlevel => 'full',
21 my $eml = PublicInbox::Eml->new(<<EOM);
23 To: $ibx->{-primary_address}
24 Date: Fri, 02 Oct 1993 0$V:0$i:0$j +0000
25 Subject: v${V}i${i}j$j
26 Message-ID: <v${V}i${i}j$j\@example>
30 $im->add($eml) or BAIL_OUT '->add';
35 my $first = shift @ibx; is($first->{name}, 'v1-3', 'first plucked');
36 my $last = pop @ibx; is($last->{name}, 'v2-6', 'last plucked');
37 my $eidx = PublicInbox::ExtSearchIdx->new("$home/eidx");
38 $eidx->attach_inbox($first);
39 $eidx->attach_inbox($last);
40 $eidx->eidx_sync({fsync => 0});
41 my $es = PublicInbox::ExtSearch->new("$home/eidx");
42 my $lxs = PublicInbox::LeiXSearch->new;
43 for my $ibxish (shuffle($es, @ibx)) {
44 $lxs->prepare_external($ibxish);
46 for my $loc ($lxs->locals) {
47 $lxs->attach_external($loc);
49 my $nr = $lxs->xdb->get_doccount;
50 my $mset = $lxs->mset('d:19931002..19931003', { limit => $nr });
51 is($mset->size, $nr, 'got all messages');
53 for my $mi ($mset->items) {
54 if (my $smsg = $lxs->smsg_for($mi)) {
57 diag "E: ${\$mi->get_docid} missing";
60 is(scalar(@msgs), $nr, 'smsgs retrieved for all');
62 $mset = $lxs->recent(undef, { limit => 1 });
63 is($mset->size, 1, 'one result');
64 my $max = max(map { $_->{docid} } @msgs);
65 is($lxs->smsg_for(($mset->items)[0])->{docid}, $max,
68 my @ibxish = $lxs->locals;
69 is(scalar(@ibxish), scalar(@ibx) + 1, 'got locals back');
70 is($lxs->search, $lxs, '->search works');
71 is($lxs->over, undef, '->over fails');
74 $lxs = PublicInbox::LeiXSearch->new;
75 my $v2ibx = create_inbox 'v2full', version => 2, sub {
76 $_[0]->add(eml_load('t/plack-qp.eml'));
78 my $v1ibx = create_inbox 'v1medium', indexlevel => 'medium', 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');