]> Sergey Matveev's repositories - public-inbox.git/commitdiff
lei q: honor --no-local to force remote searches
authorEric Wong <e@80x24.org>
Sun, 24 Jan 2021 11:46:51 +0000 (04:46 -0700)
committerEric Wong <e@80x24.org>
Sun, 24 Jan 2021 19:45:24 +0000 (15:45 -0400)
This can be useful for testing remote behavior, or for
augmenting local results.  It'll also be possible to explicitly
include/exclude externals via CLI switches (once names are
decided).

lib/PublicInbox/LeiQuery.pm
lib/PublicInbox/LeiXSearch.pm
t/lei.t

index 7713902b0e94e72b89d88851f4ff8cc93bb4ca7a..953d1fc22076f4ac77069d1c0769bf7a2107e34d 100644 (file)
@@ -26,7 +26,14 @@ sub lei_q {
                my $cb = $lxs->can('prepare_external');
                my $ne = $self->_externals_each($cb, $lxs);
                $opt->{remote} //= $ne == $lxs->remotes;
-               delete($lxs->{remotes}) if !$opt->{remote};
+               if ($opt->{'local'}) {
+                       delete($lxs->{remotes}) if !$opt->{remote};
+               } else {
+                       delete($lxs->{locals});
+               }
+       }
+       unless ($lxs->locals || $lxs->remotes) {
+               return $self->fail('no local or remote inboxes to search');
        }
        my $xj = $lxs->concurrency($opt);
        my $ovv = PublicInbox::LeiOverview->new($self) or return;
index c396c59734589b0b21bd4932da7a4688d9d3c750..0417db245d9ddb0a5e2995d53aba695e7a108d58 100644 (file)
@@ -311,7 +311,7 @@ sub start_query { # always runs in main (lei-daemon) process
                for my $ibxish (locals($self)) {
                        $self->wq_do('query_thread_mset', $io, $lei, $ibxish);
                }
-       } else {
+       } elsif (locals($self)) {
                $self->wq_do('query_mset', $io, $lei);
        }
        my $i = 0;
diff --git a/t/lei.t b/t/lei.t
index 60ca75c5da8084be83078b5679ac6176d3e0ed3f..3fd1d1fe5c1d3acc2ad1b1e104c3100888bbf5e6 100644 (file)
--- a/t/lei.t
+++ b/t/lei.t
@@ -277,6 +277,9 @@ my $test_external = sub {
        }
        ok(!$lei->('q', '-o', "$home/mbox", 's:nope'),
                        'fails if mbox format unspecified');
+       ok(!$lei->(qw(q --no-local s:see)), '--no-local');
+       is($? >> 8, 1, 'proper exit code');
+       like($err, qr/no local or remote.+? to search/, 'no inbox');
        my %e = (
                TEST_LEI_EXTERNAL_HTTPS => 'https://public-inbox.org/meta/',
                TEST_LEI_EXTERNAL_ONION => $onions[int(rand(scalar(@onions)))],