From: Eric Wong Date: Wed, 5 Mar 2025 23:26:46 +0000 (+0000) Subject: search: use common do_enquire for MiscSearch X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=1dc2441a3e0f0ddbf48bb1ffe20ed682f9a0e5bf;p=thirdparty%2Fpublic-inbox.git search: use common do_enquire for MiscSearch We can consistently use a {sort_col} search option as in xap_helper to allow do_enquire to be more generic across searches. This lets us avoid the need for a specialized implementation in MiscSearch. --- diff --git a/lib/PublicInbox/CodeSearch.pm b/lib/PublicInbox/CodeSearch.pm index 2200262d0..a80fd4b76 100644 --- a/lib/PublicInbox/CodeSearch.pm +++ b/lib/PublicInbox/CodeSearch.pm @@ -176,7 +176,8 @@ sub mset { $qry = $PublicInbox::Search::X{Query}->new( PublicInbox::Search::OP_FILTER(), $qry, 'T'.'c'); - $self->do_enquire($qry, $opt, CT); + $opt->{sort_col} = CT; + $self->do_enquire($qry, $opt); } sub roots2paths { # for diagnostics diff --git a/lib/PublicInbox/MiscSearch.pm b/lib/PublicInbox/MiscSearch.pm index ad7ebeb4e..f244e664c 100644 --- a/lib/PublicInbox/MiscSearch.pm +++ b/lib/PublicInbox/MiscSearch.pm @@ -55,23 +55,6 @@ sub mi_qp_new ($) { $qp; } -sub misc_enquire_once { # retry_reopen callback - my ($self, $qr, $opt) = @_; - my $eq = $PublicInbox::Search::X{Enquire}->new($self->{xdb}); - $eq->set_query($qr); - my $desc = !$opt->{asc}; - my $rel = $opt->{relevance} // 0; - if ($rel == -1) { # ORDER BY docid - $eq->set_docid_order($PublicInbox::Search::ENQ_ASCENDING); - $eq->set_weighting_scheme($PublicInbox::Search::X{BoolWeight}->new); - } elsif ($rel) { - $eq->set_sort_by_relevance_then_value($MODIFIED, $desc); - } else { - $eq->set_sort_by_value_then_relevance($MODIFIED, $desc); - } - $eq->get_mset($opt->{offset} || 0, $opt->{limit} || 200); -} - sub mset { my ($self, $qs, $opt) = @_; $opt ||= {}; @@ -80,7 +63,9 @@ sub mset { $qs = 'type:inbox' if $qs eq ''; my $qr = $qp->parse_query($qs, $PublicInbox::Search::QP_FLAGS); $opt->{relevance} = 1 unless exists $opt->{relevance}; - retry_reopen($self, \&misc_enquire_once, $qr, $opt); + $opt->{sort_col} = $MODIFIED; + $opt->{limit} ||= 200; + PublicInbox::Search::do_enquire($self, $qr, $opt); } sub ibx_data_once { diff --git a/lib/PublicInbox/Search.pm b/lib/PublicInbox/Search.pm index afcaabc7f..9b35c8d4e 100644 --- a/lib/PublicInbox/Search.pm +++ b/lib/PublicInbox/Search.pm @@ -454,7 +454,8 @@ sub mset { $qry = $X{Query}->new(OP_FILTER(), $qry, $X{Query}->new(OP_VALUE_RANGE(), THREADID, $tid, $tid)); } - do_enquire($self, $qry, $opt, TS); + $opt->{sort_col} //= TS; + do_enquire($self, $qry, $opt); } my %QPMETHOD_2_SYM = (add_prefix => ':', add_boolean_prefix => '='); @@ -508,10 +509,11 @@ sub async_mset { } } -sub do_enquire { # shared with CodeSearch - my ($self, $qry, $opt, $col) = @_; +sub do_enquire { # shared with CodeSearch and MiscSearch + my ($self, $qry, $opt) = @_; my $enq = $X{Enquire}->new(xdb($self)); $enq->set_query($qry); + my $col = $opt->{sort_col} // TS; my $rel = $opt->{relevance} // 0; if ($rel == -2) { # ORDER BY docid/UID (highest first) $enq->set_weighting_scheme($X{BoolWeight}->new);