unofficial mirror of meta@public-inbox.org
 help / color / mirror / Atom feed
* [PATCH] lei q: support --thread-id=$MSGID || -T $MSGID
@ 2024-04-12  2:01 Eric Wong
  2024-04-12  8:03 ` Štěpán Němec
  0 siblings, 1 reply; 3+ messages in thread
From: Eric Wong @ 2024-04-12  2:01 UTC (permalink / raw)
  To: meta

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.
---
 Documentation/lei-q.pod       |  9 +++++++++
 lib/PublicInbox/LEI.pm        |  1 +
 lib/PublicInbox/LeiXSearch.pm | 16 ++++++++++++----
 t/psgi_v2.t                   | 16 ++++++++++++++++
 4 files changed, 38 insertions(+), 4 deletions(-)

diff --git a/Documentation/lei-q.pod b/Documentation/lei-q.pod
index 4476a806..79156750 100644
--- a/Documentation/lei-q.pod
+++ b/Documentation/lei-q.pod
@@ -129,6 +129,15 @@ lei/store unless an MUA unflags it!  (Behavior undecided)
 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
diff --git a/lib/PublicInbox/LEI.pm b/lib/PublicInbox/LEI.pm
index 7c31ab43..06592358 100644
--- a/lib/PublicInbox/LEI.pm
+++ b/lib/PublicInbox/LEI.pm
@@ -177,6 +177,7 @@ our %CMD = ( # sorted in order of importance/use:
 	'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]+') ],
diff --git a/lib/PublicInbox/LeiXSearch.pm b/lib/PublicInbox/LeiXSearch.pm
index fc95d401..d4f34733 100644
--- a/lib/PublicInbox/LeiXSearch.pm
+++ b/lib/PublicInbox/LeiXSearch.pm
@@ -13,7 +13,7 @@ use File::Temp 0.19 (); # 0.19 for ->newdir
 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;
@@ -160,6 +160,8 @@ sub query_one_mset { # for --threads and l2m w/o sort
 	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;
@@ -339,6 +341,12 @@ print STDERR $_;
 	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;
@@ -459,7 +467,9 @@ sub concurrency {
 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);
 		}
@@ -546,8 +556,6 @@ sub do_query {
 	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};
diff --git a/t/psgi_v2.t b/t/psgi_v2.t
index 54faae9b..56a6ae8e 100644
--- a/t/psgi_v2.t
+++ b/t/psgi_v2.t
@@ -101,6 +101,19 @@ EOM
 	}
 };
 
+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 unlrelated 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 $!;
@@ -374,6 +387,9 @@ my $client3 = sub {
 
 	$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);

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] lei q: support --thread-id=$MSGID || -T $MSGID
  2024-04-12  2:01 [PATCH] lei q: support --thread-id=$MSGID || -T $MSGID Eric Wong
@ 2024-04-12  8:03 ` Štěpán Němec
  2024-04-12  9:43   ` Eric Wong
  0 siblings, 1 reply; 3+ messages in thread
From: Štěpán Němec @ 2024-04-12  8:03 UTC (permalink / raw)
  To: Eric Wong; +Cc: meta


Typo squad alert!

On Fri, 12 Apr 2024 02:01:03 +0000
Eric Wong wrote:

> diff --git a/t/psgi_v2.t b/t/psgi_v2.t
> index 54faae9b..56a6ae8e 100644
> --- a/t/psgi_v2.t
> +++ b/t/psgi_v2.t
> @@ -101,6 +101,19 @@ EOM
>  	}
>  };
>  
> +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 unlrelated thread';
                                                  ^
s/unlrelated/unrelated/

Thanks,

  Štěpán

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] lei q: support --thread-id=$MSGID || -T $MSGID
  2024-04-12  8:03 ` Štěpán Němec
@ 2024-04-12  9:43   ` Eric Wong
  0 siblings, 0 replies; 3+ messages in thread
From: Eric Wong @ 2024-04-12  9:43 UTC (permalink / raw)
  To: Štěpán Němec; +Cc: meta

Štěpán Němec <stepnem@smrk.net> wrote:
> Eric Wong wrote:
> > +		is $lei_out, '', 'no results on unlrelated thread';
>                                                   ^
> s/unlrelated/unrelated/

Thanks, squashed:

diff --git a/t/psgi_v2.t b/t/psgi_v2.t
index 56a6ae8e..d5c328f0 100644
--- a/t/psgi_v2.t
+++ b/t/psgi_v2.t
@@ -105,7 +105,7 @@ 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 unlrelated thread';
+		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';

And pushed as commit 873066744d1b105da4cfafb1c7312ca11b579864

^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2024-04-12  9:50 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-04-12  2:01 [PATCH] lei q: support --thread-id=$MSGID || -T $MSGID Eric Wong
2024-04-12  8:03 ` Štěpán Němec
2024-04-12  9:43   ` Eric Wong

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).