dumping ground for random patches and texts
 help / color / mirror / Atom feed
* [PATCH] mset: mbox
@ 2024-04-22  9:48 Eric Wong
  0 siblings, 0 replies; only message in thread
From: Eric Wong @ 2024-04-22  9:48 UTC (permalink / raw)
  To: spew

---
 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

^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2024-04-22  9:48 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-04-22  9:48 [PATCH] mset: mbox 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).