]> git.ipfire.org Git - thirdparty/public-inbox.git/commitdiff
www: use correct threadid for per-thread search
authorEric Wong <e@80x24.org>
Fri, 16 Jun 2023 23:13:01 +0000 (23:13 +0000)
committerEric Wong <e@80x24.org>
Sat, 17 Jun 2023 19:45:45 +0000 (19:45 +0000)
For individual public-inboxes relying on extindex for per-inbox
search, we must use the threadid from the extindex over.sqlite3
rather than the per-inbox over.sqlite3 file.

Reported-by: Konstantin Ryabitsev <konstantin@linuxfoundation.org>
Link: https://public-inbox.org/meta/20230616-rudy-comedy-vision-2b9f92@meerkat/
lib/PublicInbox/Mbox.pm
t/extindex-psgi.t

index e1abf7ec068ae4c317e3ba6f4877a90de44baf44..bf61bb0e0a56faca1383f5d30e1cf89c41d84b29 100644 (file)
@@ -225,15 +225,19 @@ sub mbox_all {
        return mbox_all_ids($ctx) if $q_string !~ /\S/;
        my $srch = $ctx->{ibx}->isrch or
                return PublicInbox::WWW::need($ctx, 'Search');
-       my $over = $ctx->{ibx}->over or
-               return PublicInbox::WWW::need($ctx, 'Overview');
 
        my $qopts = $ctx->{qopts} = { relevance => -2 }; # ORDER BY docid DESC
 
        # {threadid} limits results to a given thread
        # {threads} collapses results from messages in the same thread,
        # allowing us to use ->expand_thread w/o duplicates in our own code
-       $qopts->{threadid} = $over->mid2tid($ctx->{mid}) if defined($ctx->{mid});
+       if (defined($ctx->{mid})) {
+               my $over = ($ctx->{ibx}->{isrch} ?
+                               $ctx->{ibx}->{isrch}->{es}->over :
+                               $ctx->{ibx}->over) or
+                       return PublicInbox::WWW::need($ctx, 'Overview');
+               $qopts->{threadid} = $over->mid2tid($ctx->{mid});
+       }
        $qopts->{threads} = 1 if $q->{t};
        $srch->query_approxidate($ctx->{ibx}->git, $q_string);
        my $mset = $srch->mset($q_string, $qopts);
index 98dc2e48f313b6e0bd82274d0d0c16ed67375a0d..f10ffbb63ab2b40db78dc4f14650dcc989629137 100644 (file)
@@ -1,5 +1,5 @@
 #!perl -w
-# Copyright (C) 2020-2021 all contributors <meta@public-inbox.org>
+# Copyright (C) all contributors <meta@public-inbox.org>
 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
 use strict;
 use v5.10.1;
@@ -21,7 +21,28 @@ mkdir "$home/.public-inbox" or BAIL_OUT $!;
 my $pi_config = "$home/.public-inbox/config";
 cp($cfg_path, $pi_config) or BAIL_OUT;
 my $env = { HOME => $home };
-run_script([qw(-extindex --all), "$tmpdir/eidx"], $env) or BAIL_OUT;
+my $m2t = create_inbox 'mid2tid', version => 2, indexlevel => 'basic', sub {
+       my ($im, $ibx) = @_;
+       for my $n (1..3) {
+               $im->add(PublicInbox::Eml->new(<<EOM)) or xbail 'add';
+Date: Fri, 02 Oct 1993 00:0$n:00 +0000
+Message-ID: <t\@$n>
+Subject: tid $n
+From: x\@example.com
+References: <a-mid\@b>
+
+$n
+EOM
+               $im->add(PublicInbox::Eml->new(<<EOM)) or xbail 'add';
+Date: Fri, 02 Oct 1993 00:0$n:00 +0000
+Message-ID: <ut\@$n>
+Subject: unrelated tid $n
+From: x\@example.com
+References: <b-mid\@b>
+
+EOM
+       }
+};
 {
        open my $cfgfh, '>>', $pi_config or BAIL_OUT;
        $cfgfh->autoflush(1);
@@ -32,8 +53,14 @@ run_script([qw(-extindex --all), "$tmpdir/eidx"], $env) or BAIL_OUT;
 [publicinbox]
        wwwlisting = all
        grokManifest = all
+[publicinbox "m2t"]
+       inboxdir = $m2t->{inboxdir}
+       address = $m2t->{-primary_address}
 EOM
+       close $cfgfh or xbail "close: $!";
 }
+
+run_script([qw(-extindex --all), "$tmpdir/eidx"], $env) or BAIL_OUT;
 my $www = PublicInbox::WWW->new(PublicInbox::Config->new($pi_config));
 my $client = sub {
        my ($cb) = @_;
@@ -83,6 +110,14 @@ my $client = sub {
                't2 manifest');
        is_deeply([ sort keys %{$m->{'/t1'}} ], [ '/t1' ],
                't2 manifest');
+
+       # ensure ibx->{isrch}->{es}->over is used instead of ibx->over:
+       $res = $cb->(POST("/m2t/t\@1/?q=dt:19931002000259..&x=m"));
+       is($res->code, 200, 'hit on mid2tid query');
+       $res = $cb->(POST("/m2t/t\@1/?q=dt:19931002000400..&x=m"));
+       is($res->code, 404, '404 on out-of-range mid2tid query');
+       $res = $cb->(POST("/m2t/t\@1/?q=s:unrelated&x=m"));
+       is($res->code, 404, '404 on cross-thread search');
 };
 test_psgi(sub { $www->call(@_) }, $client);
 %$env = (%$env, TMPDIR => $tmpdir, PI_CONFIG => $pi_config);