]> Sergey Matveev's repositories - public-inbox.git/blob - t/extsearch.t
miscsearch: a new Xapian sub-DB for extindex
[public-inbox.git] / t / extsearch.t
1 #!perl -w
2 # Copyright (C) 2020 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 Test::More;
6 use PublicInbox::TestCommon;
7 use Fcntl qw(:seek);
8 require_git(2.6);
9 require_mods(qw(DBD::SQLite Search::Xapian));
10 use_ok 'PublicInbox::ExtSearch';
11 use_ok 'PublicInbox::ExtSearchIdx';
12 my ($home, $for_destroy) = tmpdir();
13 local $ENV{HOME} = $home;
14 mkdir "$home/.public-inbox" or BAIL_OUT $!;
15 open my $fh, '>', "$home/.public-inbox/config" or BAIL_OUT $!;
16 print $fh <<EOF or BAIL_OUT $!;
17 [publicinboxMda]
18         spamcheck = none
19 EOF
20 close $fh or BAIL_OUT $!;
21 my $v2addr = 'v2test@example.com';
22 my $v1addr = 'v1test@example.com';
23 ok(run_script([qw(-init -V2 v2test --newsgroup v2.example), "$home/v2test",
24         'http://example.com/v2test', $v2addr ]), 'v2test init');
25 my $env = { ORIGINAL_RECIPIENT => $v2addr };
26 open($fh, '<', 't/utf8.eml') or BAIL_OUT("open t/utf8.eml: $!");
27 run_script(['-mda', '--no-precheck'], $env, { 0 => $fh }) or BAIL_OUT '-mda';
28
29 ok(run_script([qw(-init -V1 v1test), "$home/v1test",
30         'http://example.com/v1test', $v1addr ]), 'v1test init');
31 $env = { ORIGINAL_RECIPIENT => $v1addr };
32 seek($fh, 0, SEEK_SET) or BAIL_OUT $!;
33 run_script(['-mda', '--no-precheck'], $env, { 0 => $fh }) or BAIL_OUT '-mda';
34 run_script(['-index', "$home/v1test"]) or BAIL_OUT "index $?";
35
36 ok(run_script([qw(-extindex --all), "$home/eindex"]), 'extindex init');
37
38 my $es = PublicInbox::ExtSearch->new("$home/eindex");
39 {
40         my $smsg = $es->over->get_art(1);
41         ok($smsg, 'got first article');
42         is($es->over->get_art(2), undef, 'only one added');
43         my $xref3 = $es->over->get_xref3(1);
44         like($xref3->[0], qr/\A\Qv2.example\E:1:/, 'order preserved 1');
45         like($xref3->[1], qr!\A\Q$home/v1test\E:1:!, 'order preserved 2');
46         is(scalar(@$xref3), 2, 'only to entries');
47 }
48
49 {
50         my ($in, $out, $err);
51         $in = $out = $err = '';
52         my $opt = { 0 => \$in, 1 => \$out, 2 => \$err };
53         my $env = { MAIL_EDITOR => "$^X -i -p -e 's/test message/BEST MSG/'" };
54         my $cmd = [ qw(-edit -Ft/utf8.eml), "$home/v2test" ];
55         ok(run_script($cmd, $env, $opt), '-edit');
56         ok(run_script([qw(-extindex --all), "$home/eindex"], undef, $opt),
57                 'extindex again');
58         like($err, qr/discontiguous range/, 'warned about discontiguous range');
59         my $msg1 = $es->over->get_art(1) or BAIL_OUT 'msg1 missing';
60         my $msg2 = $es->over->get_art(2) or BAIL_OUT 'msg2 missing';
61         is($msg1->{mid}, $msg2->{mid}, 'edited message indexed');
62         isnt($msg1->{blob}, $msg2->{blob}, 'blobs differ');
63         my $eml2 = $es->smsg_eml($msg2);
64         like($eml2->body, qr/BEST MSG/, 'edited body in #2');
65         unlike($eml2->body, qr/test message/, 'old body discarded in #2');
66         my $eml1 = $es->smsg_eml($msg1);
67         like($eml1->body, qr/test message/, 'original body in #1');
68         my $x1 = $es->over->get_xref3(1);
69         my $x2 = $es->over->get_xref3(2);
70         is(scalar(@$x1), 1, 'original only has one xref3');
71         is(scalar(@$x2), 1, 'new message has one xref3');
72         isnt($x1->[0], $x2->[0], 'xref3 differs');
73 }
74
75 my $misc = $es->misc;
76 is(scalar($misc->mset('')->items), 2, 'two inboxes');
77
78 done_testing;