about summary refs log tree commit homepage
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2018-07-20 06:58:45 +0000
committerEric Wong <e@80x24.org>2018-07-20 07:02:08 +0000
commitea54cfe8dad656021517b32c76f0893979fb001b (patch)
tree6d12a86947e52e414d35bbac7587f9e7801e7fdd
parent4caa768779a9b417321736b090d50f3421a799de (diff)
downloadpublic-inbox-ea54cfe8dad656021517b32c76f0893979fb001b.tar.gz
For v1 repos, we don't need to write any metadata to Xapian
and changing from 'basic' to 'medium' or 'full' will work.

For v2, the metadata for indexing is stored in msgmap (because
the Xapian databases are partitioned for parallelism), so a
reindex is required.
-rw-r--r--lib/PublicInbox/SearchIdx.pm5
-rw-r--r--t/v1reindex.t21
2 files changed, 23 insertions, 3 deletions
diff --git a/lib/PublicInbox/SearchIdx.pm b/lib/PublicInbox/SearchIdx.pm
index bb60506c..1d259a86 100644
--- a/lib/PublicInbox/SearchIdx.pm
+++ b/lib/PublicInbox/SearchIdx.pm
@@ -27,6 +27,8 @@ use constant {
         DEBUG => !!$ENV{DEBUG},
 };
 
+my $xapianlevels = qr/\A(?:full|medium)\z/;
+
 my %GIT_ESC = (
         a => "\a",
         b => "\b",
@@ -365,7 +367,6 @@ sub add_xapian ($$$$$) {
 sub add_message {
         # mime = Email::MIME object
         my ($self, $mime, $bytes, $num, $oid, $mid0) = @_;
-        my $xapianlevels = qr/\A(?:full|medium)\z/;
         my $mids = mids($mime->header_obj);
         $mid0 = $mids->[0] unless defined $mid0; # v1 compatibility
         unless (defined $num) { # v1
@@ -714,7 +715,7 @@ sub _index_sync {
                         }
                         $dbh->commit;
                 }
-                if ($mkey && $newest) {
+                if ($mkey && $newest && $self->{indexlevel} =~ $xapianlevels) {
                         my $cur = $xdb->get_metadata($mkey);
                         if (need_update($self, $cur, $newest)) {
                                 $xdb->set_metadata($mkey, $newest);
diff --git a/t/v1reindex.t b/t/v1reindex.t
index d97938d3..75380f0f 100644
--- a/t/v1reindex.t
+++ b/t/v1reindex.t
@@ -124,9 +124,10 @@ $rw = PublicInbox::SearchIdx->new($ibx, 1);
         ok(-d $xap, 'Xapian directories recreated');
         delete $ibx->{mm};
         is_deeply([ $ibx->mm->minmax ], $minmax, 'minmax unchanged');
+        my $mset = $ibx->search->query('hello world', {mset=>1});
+        isnt(0, $mset->size, 'got Xapian search results');
 }
 
-
 ok(unlink "$mainrepo/public-inbox/msgmap.sqlite3", 'remove msgmap');
 remove_tree($xap);
 ok(!-d $xap, 'Xapian directories removed again');
@@ -144,7 +145,25 @@ $rw = PublicInbox::SearchIdx->new($ibx, 1);
         ok(-d $xap, 'Xapian directories recreated');
         delete $ibx->{mm};
         is_deeply([ $ibx->mm->minmax ], $minmax, 'minmax unchanged');
+        my $mset = $ibx->search->reopen->query('hello world', {mset=>1});
+        is(0, $mset->size, "no Xapian search results");
 }
 
+# upgrade existing basic to medium
+# note: changing indexlevels is not yet supported in v2,
+# and may not be without more effort
+$ibx_config->{indexlevel} = 'medium';
+$ibx = PublicInbox::Inbox->new($ibx_config);
+$rw = PublicInbox::SearchIdx->new($ibx, 1);
+# no removals
+{
+        my @warn;
+        local $SIG{__WARN__} = sub { push @warn, @_ };
+        eval { $rw->index_sync };
+        is($@, '', 'no error from indexing');
+        is_deeply(\@warn, [], 'no warnings');
+        my $mset = $ibx->search->reopen->query('hello world', {mset=>1});
+        isnt(0, $mset->size, 'search OK after basic -> medium');
+}
 
 done_testing();