dumping ground for random patches and texts
 help / color / mirror / Atom feed
From: Eric Wong <e@80x24.org>
To: spew@80x24.org
Subject: [PATCH 6/8] mset: mbox
Date: Wed, 24 Apr 2024 01:34:18 +0000	[thread overview]
Message-ID: <20240424013420.476353-6-e@80x24.org> (raw)
In-Reply-To: <20240424013420.476353-1-e@80x24.org>

---
 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 ac565df9..e58fb4b6 100644
--- a/lib/PublicInbox/Mbox.pm
+++ b/lib/PublicInbox/Mbox.pm
@@ -213,14 +213,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,
@@ -230,25 +252,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 88693741..5a89544a 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

  parent reply	other threads:[~2024-04-24  1:34 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-04-24  1:34 [PATCH 1/8] searchview: get rid of unused adump callback arg Eric Wong
2024-04-24  1:34 ` [PATCH 2/8] xap_helper.h: remove _SC_NPROCESSORS_ONLN default Eric Wong
2024-04-24  1:34 ` [PATCH 3/8] xap_helper: drop terms+data from `mset' command Eric Wong
2024-04-24  1:34 ` [PATCH 4/8] mbox: hoist out refill_result_ids Eric Wong
2024-04-24  1:34 ` [PATCH 5/8] www: start wiring up search to use async xap_helper Eric Wong
2024-04-24  1:34 ` Eric Wong [this message]
2024-04-24  1:34 ` [PATCH 7/8] WIP thread bad mbox Eric Wong
2024-04-24  1:34 ` [PATCH 8/8] mbox: fixup Eric Wong

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=20240424013420.476353-6-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).