2 # Copyright (C) 2017-2021 all contributors <meta@public-inbox.org>
3 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
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::Smsg;
13 require PublicInbox::Inbox;
14 use PublicInbox::Import;
15 my ($tmpdir, $for_destroy) = tmpdir();
16 my $git_dir = "$tmpdir/a.git";
18 PublicInbox::Import::init_bare($git_dir);
19 my $ibx = PublicInbox::Inbox->new({inboxdir => $git_dir});
20 my $rw = PublicInbox::SearchIdx->new($ibx, 1);
21 ok($rw, "search indexer created");
39 # nb. using internal API, fragile!
40 my $xdb = $rw->begin_txn_lazy;
43 foreach (reverse split(/\n\n/, $data)) {
45 my $mime = PublicInbox::Eml->new(\$_);
46 $mime->header_set('From' => 'bw@g');
47 $mime->header_set('To' => 'git@vger.kernel.org');
48 my $bytes = length($mime->as_string);
49 my $mid = mids($mime->header_obj)->[0];
55 }, 'PublicInbox::Smsg';
56 my $doc_id = $rw->add_message($mime, $smsg);
58 ok($doc_id, 'message added: '. $mid);
63 my $dbh = $rw->{oidx}->dbh;
64 foreach my $mid (@mids) {
65 my $msgs = $rw->{oidx}->get_thread($mid);
66 is(3, scalar(@$msgs), "got all messages from $mid");
67 foreach my $m (@$msgs) {
68 my $tid = $dbh->selectrow_array(<<'', undef, $m->{num});
69 SELECT tid FROM over WHERE num = ? LIMIT 1
75 is(scalar keys %tids, 1, 'all messages have the same tid');
79 $xdb = $rw->begin_txn_lazy;
81 my $mime = PublicInbox::Eml->new(<<'');
85 To: git@vger.kernel.org
87 my $dbh = $rw->{oidx}->dbh;
89 my $reidx = $rw->{oidx}->next_by_mid('1-bw@g', \$id, \$prev);
91 my $num = $reidx->{num};
92 my $tid0 = $dbh->selectrow_array(<<'', undef, $num);
93 SELECT tid FROM over WHERE num = ? LIMIT 1
95 my $bytes = length($mime->as_string);
96 my $mid = mids($mime->header_obj)->[0];
102 }, 'PublicInbox::Smsg';
103 my $doc_id = $rw->add_message($mime, $smsg);
104 ok($doc_id, 'message reindexed'. $mid);
105 is($doc_id, $num, "article number unchanged: $num");
107 my $tid1 = $dbh->selectrow_array(<<'', undef, $num);
108 SELECT tid FROM over WHERE num = ? LIMIT 1
110 is($tid1, $tid0, 'tid unchanged on reindex');
113 $rw->commit_txn_lazy;