1 # Copyright (C) 2018 all contributors <meta@public-inbox.org>
2 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
7 use PublicInbox::ContentId qw(content_digest);
8 use File::Temp qw/tempdir/;
9 use File::Path qw(remove_tree);
11 foreach my $mod (qw(DBD::SQLite Search::Xapian)) {
13 plan skip_all => "$mod missing for v1reindex.t" if $@;
15 use_ok 'PublicInbox::SearchIdx';
16 use_ok 'PublicInbox::Import';
17 my $mainrepo = tempdir('pi-v1reindex-XXXXXX', TMPDIR => 1, CLEANUP => 1);
18 is(system(qw(git init -q --bare), $mainrepo), 0);
20 mainrepo => $mainrepo,
21 name => 'test-v1reindex',
22 -primary_address => 'test@example.com',
25 my $mime = PublicInbox::MIME->create(
27 From => 'a@example.com',
28 To => 'test@example.com',
29 Subject => 'this is a subject',
30 Date => 'Fri, 02 Oct 1993 00:00:00 +0000',
32 body => "hello world\n",
36 my %config = %$ibx_config;
37 my $ibx = PublicInbox::Inbox->new(\%config);
38 my $im = PublicInbox::Import->new($ibx->git, undef, undef, $ibx);
39 foreach my $i (1..10) {
40 $mime->header_set('Message-Id', "<$i\@example.com>");
41 ok($im->add($mime), "message $i added");
47 if ('test remove later') {
48 $mime->header_set('Message-Id', "<5\@example.com>");
53 my $rw = PublicInbox::SearchIdx->new($ibx, 1);
54 eval { $rw->index_sync() };
55 is($@, '', 'no error from indexing');
57 $minmax = [ $ibx->mm->minmax ];
58 ok(defined $minmax->[0] && defined $minmax->[1], 'minmax defined');
59 is_deeply($minmax, [ 1, 10 ], 'minmax as expected');
63 my %config = %$ibx_config;
64 my $ibx = PublicInbox::Inbox->new(\%config);
65 my $im = PublicInbox::Import->new($ibx->git, undef, undef, $ibx);
66 my $rw = PublicInbox::SearchIdx->new($ibx, 1);
67 eval { $rw->index_sync({reindex => 1}) };
68 is($@, '', 'no error from reindexing');
72 my $xap = "$mainrepo/public-inbox/xapian".PublicInbox::Search::SCHEMA_VERSION();
74 ok(!-d $xap, 'Xapian directories removed');
76 my %config = %$ibx_config;
77 my $ibx = PublicInbox::Inbox->new(\%config);
78 my $im = PublicInbox::Import->new($ibx->git, undef, undef, $ibx);
79 my $rw = PublicInbox::SearchIdx->new($ibx, 1);
81 eval { $rw->index_sync({reindex => 1}) };
82 is($@, '', 'no error from reindexing');
84 ok(-d $xap, 'Xapian directories recreated');
87 is_deeply([ $ibx->mm->minmax ], $minmax, 'minmax unchanged');
90 ok(unlink "$mainrepo/public-inbox/msgmap.sqlite3", 'remove msgmap');
92 ok(!-d $xap, 'Xapian directories removed again');
95 local $SIG{__WARN__} = sub { push @warn, @_ };
96 my %config = %$ibx_config;
97 my $ibx = PublicInbox::Inbox->new(\%config);
98 my $im = PublicInbox::Import->new($ibx->git, undef, undef, $ibx);
99 my $rw = PublicInbox::SearchIdx->new($ibx, 1);
100 eval { $rw->index_sync({reindex => 1}) };
101 is($@, '', 'no error from reindexing without msgmap');
102 is(scalar(@warn), 0, 'no warnings from reindexing');
104 ok(-d $xap, 'Xapian directories recreated');
106 is_deeply([ $ibx->mm->minmax ], $minmax, 'minmax unchanged');
109 ok(unlink "$mainrepo/public-inbox/msgmap.sqlite3", 'remove msgmap');
111 ok(!-d $xap, 'Xapian directories removed again');
114 local $SIG{__WARN__} = sub { push @warn, @_ };
115 my %config = %$ibx_config;
116 my $ibx = PublicInbox::Inbox->new(\%config);
117 my $im = PublicInbox::Import->new($ibx->git, undef, undef, $ibx);
118 my $rw = PublicInbox::SearchIdx->new($ibx, 1);
119 eval { $rw->index_sync({reindex => 1}) };
120 is($@, '', 'no error from reindexing without msgmap');
121 is_deeply(\@warn, [], 'no warnings');
123 ok(-d $xap, 'Xapian directories recreated');
125 is_deeply([ $ibx->mm->minmax ], $minmax, 'minmax unchanged');
128 ok(unlink "$mainrepo/public-inbox/msgmap.sqlite3", 'remove msgmap');
130 ok(!-d $xap, 'Xapian directories removed again');
133 local $SIG{__WARN__} = sub { push @warn, @_ };
134 my %config = %$ibx_config;
135 $config{indexlevel} = 'medium';
136 my $ibx = PublicInbox::Inbox->new(\%config);
137 my $im = PublicInbox::Import->new($ibx->git, undef, undef, $ibx);
138 my $rw = PublicInbox::SearchIdx->new($ibx, 1);
139 eval { $rw->index_sync({reindex => 1}) };
140 is($@, '', 'no error from reindexing without msgmap');
141 is_deeply(\@warn, [], 'no warnings');
143 ok(-d $xap, 'Xapian directories recreated');
145 is_deeply([ $ibx->mm->minmax ], $minmax, 'minmax unchanged');
146 my $mset = $ibx->search->query('hello world', {mset=>1});
147 isnt(0, $mset->size, 'got Xapian search results');
150 ok(unlink "$mainrepo/public-inbox/msgmap.sqlite3", 'remove msgmap');
152 ok(!-d $xap, 'Xapian directories removed again');
155 local $SIG{__WARN__} = sub { push @warn, @_ };
156 my %config = %$ibx_config;
157 $config{indexlevel} = 'basic';
158 my $ibx = PublicInbox::Inbox->new(\%config);
159 my $im = PublicInbox::Import->new($ibx->git, undef, undef, $ibx);
160 my $rw = PublicInbox::SearchIdx->new($ibx, 1);
161 eval { $rw->index_sync({reindex => 1}) };
162 is($@, '', 'no error from reindexing without msgmap');
163 is_deeply(\@warn, [], 'no warnings');
165 ok(-d $xap, 'Xapian directories recreated');
167 is_deeply([ $ibx->mm->minmax ], $minmax, 'minmax unchanged');
168 my $mset = $ibx->search->reopen->query('hello world', {mset=>1});
169 is(0, $mset->size, "no Xapian search results");
172 # upgrade existing basic to medium
173 # note: changing indexlevels is not yet supported in v2,
174 # and may not be without more effort
178 local $SIG{__WARN__} = sub { push @warn, @_ };
179 my %config = %$ibx_config;
180 $config{indexleve} = 'medium';
181 my $ibx = PublicInbox::Inbox->new(\%config);
182 my $rw = PublicInbox::SearchIdx->new($ibx, 1);
183 eval { $rw->index_sync };
184 is($@, '', 'no error from indexing');
185 is_deeply(\@warn, [], 'no warnings');
186 my $mset = $ibx->search->reopen->query('hello world', {mset=>1});
187 isnt(0, $mset->size, 'search OK after basic -> medium');