This adds support for the "POST /$INBOX/$MSGID/?x=m?q=..."
added last year to support per-thread searches
764035c83 (www: support POST /$INBOX/$MSGID/?x=m&q=, 2023-03-30)
This only supports instances of public-inbox since
764035c83,
but unfortunately there hasn't been a release since then.
Caveat: C<-tt> only works on locally-indexed messages at the
moment, and not on remote (HTTP(S)) endpoints.
+=item --thread-id=MSGID
+
+=item -T MSGID
+
+Only search messages in the same thread as the given Message-ID.
+
+For HTTP(S) externals, this only works on instances running
+public-inbox 2.0+ (UNRELEASED).
+
=item --jobs=QUERY_WORKERS[,WRITE_WORKERS]
=item --jobs=,WRITE_WORKERS
'stdin|', # /|\z/ must be first for lone dash
@lxs_opt, @net_opt,
qw(save! output|mfolder|o=s format|f=s dedupe|d=s threads|t+
+ thread-id|T=s
sort|s=s reverse|r offset=i pretty jobs|j=s globoff|g augment|a
import-before! lock=s@ rsyncable alert=s@ mua=s verbose|v+
shared color! mail-sync!), @c_opt, opt_dash('limit|n=i', '[0-9]+') ],
use File::Spec ();
use PublicInbox::Search qw(xap_terms);
use PublicInbox::Spawn qw(popen_rd popen_wr which);
-use PublicInbox::MID qw(mids);
+use PublicInbox::MID qw(mids mid_escape);
use PublicInbox::Smsg;
use PublicInbox::Eml;
use PublicInbox::LEI;
my $can_kw = !!$ibxish->can('msg_keywords');
my $threads = $lei->{opt}->{threads} // 0;
my $fl = $threads > 1 ? 1 : undef;
+ my $mid = $lei->{opt}->{'thread-id'};
+ $mo->{threadid} = $over->mid2tid($mid) if defined $mid;
my $lss = $lei->{lss};
my $maxk = "external.$dir.maxuid"; # max of previous, so our min
my $min = $lss ? ($lss->{-cfg}->{$maxk} // 0) : 0;
push @$curl, '-s', '-d', '';
my $each_smsg = $lei->{ovv}->ovv_each_smsg_cb($lei);
$self->{import_sto} = $lei->{sto} if $lei->{opt}->{'import-remote'};
+ if (defined(my $mid = $opt->{'thread-id'})) {
+ $mid = mid_escape($mid);
+ for my $uri (@$uris) {
+ $uri->path($uri->path.$mid.'/');
+ }
+ }
for my $uri (@$uris) {
$lei->{-current_url} = $uri->as_string;
my $start = time;
sub start_query ($$) { # always runs in main (lei-daemon) process
my ($self, $lei) = @_;
local $PublicInbox::LEI::current_lei = $lei;
- if ($self->{opt_threads} || ($lei->{l2m} && !$self->{opt_sort})) {
+ if ($lei->{opt}->{threads} ||
+ defined($lei->{opt}->{'thread-id'}) ||
+ ($lei->{l2m} && !$lei->{opt}->{'sort'})) {
for my $ibxish (locals($self)) {
$self->wq_io_do('query_one_mset', [], $ibxish);
}
my $op_c = delete $lei->{pkt_op_c};
delete $lei->{pkt_op_p};
@$end = ();
- $self->{opt_threads} = $lei->{opt}->{threads};
- $self->{opt_sort} = $lei->{opt}->{'sort'};
$self->{-do_lcat} = !!(delete $lei->{lcat_todo});
if ($l2m) {
$l2m->net_merge_all_done($lei) unless $lei->{auth};
}
};
+my $test_lei_q_threadid = sub {
+ my ($u) = @_;
+ test_lei(sub {
+ lei_ok qw(q -f text --only), $u, qw(-T t@1 s:unrelated);
+ is $lei_out, '', 'no results on unrelated thread';
+ lei_ok qw(q -f text --only), $u, qw(-T t@1 dt:19931002000300..);
+ my @m = ($lei_out =~ m!^Message-ID: <([^>]+)>\n!gms);
+ is_deeply \@m, ['t@3'], 'got expected result from -T MSGID';
+ });
+};
+
+$test_lei_q_threadid->($m2t->{inboxdir});
+
my $cfgpath = "$ibx->{inboxdir}/pi_config";
{
open my $fh, '>', $cfgpath or BAIL_OUT $!;
$res = $cb->(POST("/m2t/t\@1/?q=s:unrelated&x=m"));
is($res->code, 404, '404 on cross-thread search');
+
+ my $rmt = $ENV{PLACK_TEST_EXTERNALSERVER_URI};
+ $rmt and $test_lei_q_threadid->("$rmt/m2t/");
};
test_psgi(sub { $www->call(@_) }, $client3);
test_httpd($env, $client3, 4);