From aad1b9e70529b78d3d7d62b0920ad82ca40f9592 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Sat, 22 Aug 2020 06:06:26 +0000 Subject: search: support downloading mboxes results with full thread Finally, the addition of THREADID for collapsing results in Xapian lets us emulate the "mairix --threads" feature. That is, instead of returning only the matching messages, the entire thread is included in the downloaded mbox.gz This requires a "public-inbox-index --reindex" to be usable. --- lib/PublicInbox/Over.pm | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) (limited to 'lib/PublicInbox/Over.pm') diff --git a/lib/PublicInbox/Over.pm b/lib/PublicInbox/Over.pm index 34d0b05d..fba58d17 100644 --- a/lib/PublicInbox/Over.pm +++ b/lib/PublicInbox/Over.pm @@ -179,6 +179,35 @@ ORDER BY $sort_col DESC ($nr, $msgs); } +# strict `tid' matches, only, for thread-expanded mbox.gz search results +# and future CLI interface +# returns true if we have IDs, undef if not +sub expand_thread { + my ($self, $ctx) = @_; + my $dbh = $self->connect; + do { + defined(my $num = $ctx->{ids}->[0]) or return; + my ($tid) = $dbh->selectrow_array(<<'', undef, $num); +SELECT tid FROM over WHERE num = ? + + if (defined($tid)) { + my $sql = <<''; +SELECT num FROM over WHERE tid = ? AND num > ? +ORDER BY num ASC LIMIT 1000 + + my $xids = $dbh->selectcol_arrayref($sql, undef, $tid, + $ctx->{prev} // 0); + if (scalar(@$xids)) { + $ctx->{prev} = $xids->[-1]; + $ctx->{xids} = $xids; + return 1; # success + } + } + $ctx->{prev} = 0; + shift @{$ctx->{ids}}; + } while (1); +} + sub recent { my ($self, $opts, $after, $before) = @_; my ($s, @v); -- cgit v1.2.3-24-ge0c7