]> Sergey Matveev's repositories - public-inbox.git/blob - t/lei_xsearch.t
update copyrights for 2021
[public-inbox.git] / t / lei_xsearch.t
1 #!perl -w
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>
4 use strict;
5 use v5.10.1;
6 use Test::More;
7 use List::Util qw(shuffle max);
8 use PublicInbox::TestCommon;
9 use PublicInbox::ExtSearchIdx;
10 use PublicInbox::Eml;
11 use PublicInbox::InboxWritable;
12 require_mods(qw(DBD::SQLite Search::Xapian));
13 require_git 2.6;
14 require_ok 'PublicInbox::LeiXSearch';
15 my ($home, $for_destroy) = tmpdir();
16 my @ibx;
17 for my $V (1..2) {
18         for my $i (3..6) {
19                 my $ibx = PublicInbox::InboxWritable->new({
20                         inboxdir => "$home/v$V-$i",
21                         name => "test-v$V-$i",
22                         version => $V,
23                         indexlevel => 'medium',
24                         -primary_address => "v$V-$i\@example.com",
25                 }, { nproc => int(rand(8)) + 1 });
26                 push @ibx, $ibx;
27                 my $im = $ibx->importer(0);
28                 for my $j (0..9) {
29                         my $eml = PublicInbox::Eml->new(<<EOF);
30 From: x\@example.com
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>
35
36 ${V}er ${i}on j$j
37 EOF
38                         $im->add($eml);
39                 }
40                 $im->done;
41         }
42 }
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);
53 }
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');
57 my @msgs;
58 for my $mi ($mset->items) {
59         if (my $smsg = $lxs->smsg_for($mi)) {
60                 push @msgs, $smsg;
61         } else {
62                 diag "E: ${\$mi->get_docid} missing";
63         }
64 }
65 is(scalar(@msgs), $nr, 'smsgs retrieved for all');
66
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,
71         'got highest docid');
72
73 done_testing;