1 # Copyright (C) 2017-2020 all contributors <meta@public-inbox.org>
2 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
5 use bytes (); # only for bytes::length
7 use PublicInbox::TestCommon;
8 use PublicInbox::MID qw(mids);
10 require_mods(qw(DBD::SQLite Search::Xapian));
11 require PublicInbox::SearchIdx;
12 require PublicInbox::Inbox;
13 my ($tmpdir, $for_destroy) = tmpdir();
14 my $git_dir = "$tmpdir/a.git";
16 is(0, system(qw(git init -q --bare), $git_dir), "git init (main)");
17 my $ibx = PublicInbox::Inbox->new({inboxdir => $git_dir});
18 my $rw = PublicInbox::SearchIdx->new($ibx, 1);
19 ok($rw, "search indexer created");
37 # nb. using internal API, fragile!
38 my $xdb = $rw->begin_txn_lazy;
41 foreach (reverse split(/\n\n/, $data)) {
43 my $mime = Email::MIME->new(\$_);
44 $mime->header_set('From' => 'bw@g');
45 $mime->header_set('To' => 'git@vger.kernel.org');
46 my $bytes = bytes::length($mime->as_string);
47 my $mid = mids($mime->header_obj)->[0];
48 my $doc_id = $rw->add_message($mime, $bytes, ++$num, 'ignored', $mid);
50 ok($doc_id, 'message added: '. $mid);
55 my $dbh = $rw->{over}->connect;
56 foreach my $mid (@mids) {
57 my $msgs = $rw->{over}->get_thread($mid);
58 is(3, scalar(@$msgs), "got all messages from $mid");
59 foreach my $m (@$msgs) {
60 my $tid = $dbh->selectrow_array(<<'', undef, $m->{num});
61 SELECT tid FROM over WHERE num = ? LIMIT 1
67 is(scalar keys %tids, 1, 'all messages have the same tid');
71 $xdb = $rw->begin_txn_lazy;
73 my $mime = Email::MIME->new(<<'');
77 To: git@vger.kernel.org
79 my $dbh = $rw->{over}->connect;
81 my $reidx = $rw->{over}->next_by_mid('1-bw@g', \$id, \$prev);
83 my $num = $reidx->{num};
84 my $tid0 = $dbh->selectrow_array(<<'', undef, $num);
85 SELECT tid FROM over WHERE num = ? LIMIT 1
87 my $bytes = bytes::length($mime->as_string);
88 my $mid = mids($mime->header_obj)->[0];
89 my $doc_id = $rw->add_message($mime, $bytes, $num, 'ignored', $mid);
90 ok($doc_id, 'message reindexed'. $mid);
91 is($doc_id, $num, "article number unchanged: $num");
93 my $tid1 = $dbh->selectrow_array(<<'', undef, $num);
94 SELECT tid FROM over WHERE num = ? LIMIT 1
96 is($tid1, $tid0, 'tid unchanged on reindex');