]> git.ipfire.org Git - thirdparty/public-inbox.git/commitdiff
search: use common do_enquire for MiscSearch
authorEric Wong <e@80x24.org>
Wed, 5 Mar 2025 23:26:46 +0000 (23:26 +0000)
committerEric Wong <e@80x24.org>
Fri, 7 Mar 2025 19:23:15 +0000 (19:23 +0000)
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.

lib/PublicInbox/CodeSearch.pm
lib/PublicInbox/MiscSearch.pm
lib/PublicInbox/Search.pm

index 2200262d0599e859e8ce0392bee59b98efe2e91a..a80fd4b76aa316aee1e4bfe60ad57995ae51518f 100644 (file)
@@ -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
index ad7ebeb4e0d8896a4ac53ec77e661684390b302a..f244e664c2e78bc88c39c545ed16a5536dfb7290 100644 (file)
@@ -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 {
index afcaabc7f9e30f1c8e1d1d7a27786c8ff31002f6..9b35c8d4ebec5a370956d811b0617684a7c43b88 100644 (file)
@@ -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);