From: Eric Wong <e@80x24.org>
To: spew@80x24.org
Subject: [PATCH] mset: mbox
Date: Mon, 22 Apr 2024 09:48:14 +0000 [thread overview]
Message-ID: <20240422094814.223544-1-e@80x24.org> (raw)
---
lib/PublicInbox/Mbox.pm | 58 ++++++++++++++++++++++--------------
lib/PublicInbox/Search.pm | 2 ++
lib/PublicInbox/xap_helper.h | 7 +++++
3 files changed, 44 insertions(+), 23 deletions(-)
diff --git a/lib/PublicInbox/Mbox.pm b/lib/PublicInbox/Mbox.pm
index 52f88ae3..4a0f4681 100644
--- a/lib/PublicInbox/Mbox.pm
+++ b/lib/PublicInbox/Mbox.pm
@@ -217,14 +217,36 @@ sub results_thread_cb {
}
+sub mbox_qry_cb { # async_mset cb
+ my ($ctx, $opt, $q, $mset, $err) = @_;
+ my $wcb = delete $ctx->{wcb};
+ if ($err) {
+ warn "E: $err";
+ return $wcb->([500, [qw(Content-Type text/plain)],
+ [ "Internal server error\n" ]])
+ }
+ $opt->{offset} = $mset->size or
+ return $wcb->([404, [qw(Content-Type text/plain)],
+ ["No results found\n"]]);
+ $ctx->{ids} = $ctx->{srch}->mset_to_artnums($mset, $opt);
+ my @cb_fn;
+ if ($q->{t} && $ctx->{srch}->has_threadid) {
+ @cb_fn = (\&results_thread_cb, "results-thread-$ctx->{query}");
+ } else {
+ @cb_fn = (\&results_cb, "results-$ctx->{query}");
+ }
+ require PublicInbox::MboxGz;
+ my $res = PublicInbox::MboxGz::mbox_gz($ctx, @cb_fn);
+ ref($res) eq 'CODE' ? $res->($wcb) : $wcb->($res);
+}
+
sub mbox_all {
my ($ctx, $q) = @_;
- my $q_string = $q->{'q'};
- return mbox_all_ids($ctx) if $q_string !~ /\S/;
- my $srch = $ctx->{ibx}->isrch or
+ my $qstr = $q->{'q'};
+ return mbox_all_ids($ctx) if $qstr !~ /\S/;
+ my $srch = $ctx->{srch} = $ctx->{ibx}->isrch or
return PublicInbox::WWW::need($ctx, 'Search');
-
- my $qopts = $ctx->{qopts} = { relevance => -2 }; # ORDER BY docid DESC
+ my $opt = $ctx->{qopts} = { relevance => -2 }; # ORDER BY docid DESC
# {threadid} limits results to a given thread
# {threads} collapses results from messages in the same thread,
@@ -234,25 +256,15 @@ sub mbox_all {
$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);
- $qopts->{offset} = $mset->size or
- return [404, [qw(Content-Type text/plain)],
- ["No results found\n"]];
- $ctx->{query} = $q_string;
- $ctx->{ids} = $srch->mset_to_artnums($mset, $qopts);
- require PublicInbox::MboxGz;
- my $fn;
- if ($q->{t} && $srch->has_threadid) {
- $fn = 'results-thread-'.$q_string;
- PublicInbox::MboxGz::mbox_gz($ctx, \&results_thread_cb, $fn);
- } else {
- $fn = 'results-'.$q_string;
- PublicInbox::MboxGz::mbox_gz($ctx, \&results_cb, $fn);
+ $opt->{threadid} = $over->mid2tid($ctx->{mid});
}
+ $opt->{threads} = 1 if $q->{t};
+ $srch->query_approxidate($ctx->{ibx}->git, $qstr);
+ $ctx->{query} = $qstr;
+ sub {
+ $ctx->{wcb} = $_[0]; # PSGI server supplied write cb
+ $srch->async_mset($qstr, $opt, \&mbox_qry_cb, $ctx, $opt, $q);
+ };
}
1;
diff --git a/lib/PublicInbox/Search.pm b/lib/PublicInbox/Search.pm
index f29555d1..5c417be3 100644
--- a/lib/PublicInbox/Search.pm
+++ b/lib/PublicInbox/Search.pm
@@ -449,9 +449,11 @@ sub xh_opt ($) {
push @ret, '-a';
} elsif ($rel == 0) {
push @ret, '-k', $opt->{sort_col} // TS;
+ push @ret, '-a' if $opt->{asc};
} else { # rel > 0
push @ret, '-r';
push @ret, '-k', $opt->{sort_col} // TS;
+ push @ret, '-a' if $opt->{asc};
}
push @ret, '-t' if $opt->{threads};
push @ret, '-T', $opt->{threadid} if defined $opt->{threadid};
diff --git a/lib/PublicInbox/xap_helper.h b/lib/PublicInbox/xap_helper.h
index 3b30e980..fb48f86f 100644
--- a/lib/PublicInbox/xap_helper.h
+++ b/lib/PublicInbox/xap_helper.h
@@ -224,6 +224,13 @@ static Xapian::MSet mail_mset(struct req *req, const char *qry_str)
qry = Xapian::Query(Xapian::Query::OP_FILTER, qry,
Xapian::Query(req->Oeidx_key));
}
+ // TODO: uid_range
+ if (req->threadid != ULLONG_MAX) {
+ std::string tid = Xapian::sortable_serialise(req->threadid);
+ qry = Xapian::Query(Xapian::Query::OP_FILTER, qry,
+ Xapian::Query(Xapian::Query::OP_VALUE_RANGE, THREADID,
+ tid, tid));
+ }
Xapian::Enquire enq = prep_enquire(req);
enq.set_query(qry);
// THREADID is a CPP macro defined on CLI (see) XapHelperCxx.pm
reply other threads:[~2024-04-22 9:48 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240422094814.223544-1-e@80x24.org \
--to=e@80x24.org \
--cc=spew@80x24.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).