about summary refs log tree commit homepage
path: root/lib
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2020-09-02 11:04:16 +0000
committerEric Wong <e@80x24.org>2020-09-03 20:11:03 +0000
commit80b887f29b2ec71d025b4c266a1c26314758994c (patch)
tree31f9937daf20c21b33c0407763bf2d6bd06d2f66 /lib
parent851aa7183cf2b152d7ff187729bc896597d22fad (diff)
downloadpublic-inbox-80b887f29b2ec71d025b4c266a1c26314758994c.tar.gz
search: replace ->query with ->mset
Nearly all of the search uses in the production code rely on
a Xapian mset iterator being returned (instead of an array
of $smsg objects).  So default to returning the mset and move
the burden of smsg array conversion into the test cases.
Diffstat (limited to 'lib')
-rw-r--r--lib/PublicInbox/ExtMsg.pm4
-rw-r--r--lib/PublicInbox/IMAP.pm2
-rw-r--r--lib/PublicInbox/Mbox.pm6
-rw-r--r--lib/PublicInbox/Search.pm12
-rw-r--r--lib/PublicInbox/SearchView.pm3
-rw-r--r--lib/PublicInbox/SolverGit.pm5
6 files changed, 15 insertions, 17 deletions
diff --git a/lib/PublicInbox/ExtMsg.pm b/lib/PublicInbox/ExtMsg.pm
index 65892161..5dffc65c 100644
--- a/lib/PublicInbox/ExtMsg.pm
+++ b/lib/PublicInbox/ExtMsg.pm
@@ -65,10 +65,10 @@ sub search_partial ($$) {
                 # has too many results.  $@ can be
                 # Search::Xapian::QueryParserError or even:
                 # "something terrible happened at ../Search/Xapian/Enquire.pm"
-                my $mset = eval { $srch->query($m, $opt) } or next;
+                my $mset = eval { $srch->mset($m, $opt) } or next;
                 my @mids = map {
                         $_->{mid}
-                } @{$ibx->over->get_all(@{$srch->mset_to_artnums($mset)})};
+                } @{$srch->mset_to_smsg($ibx, $mset)};
                 return \@mids if scalar(@mids);
         }
 }
diff --git a/lib/PublicInbox/IMAP.pm b/lib/PublicInbox/IMAP.pm
index abdb8fec..d540fd0b 100644
--- a/lib/PublicInbox/IMAP.pm
+++ b/lib/PublicInbox/IMAP.pm
@@ -1187,7 +1187,7 @@ sub refill_xap ($$$$) {
         my ($beg, $end) = @$range_info;
         my $srch = $self->{ibx}->search;
         my $opt = { mset => 2, limit => 1000 };
-        my $mset = $srch->query("$q uid:$beg..$end", $opt);
+        my $mset = $srch->mset("$q uid:$beg..$end", $opt);
         @$uids = @{$srch->mset_to_artnums($mset)};
         if (@$uids) {
                 $range_info->[0] = $uids->[-1] + 1; # update $beg
diff --git a/lib/PublicInbox/Mbox.pm b/lib/PublicInbox/Mbox.pm
index 0223bead..47025891 100644
--- a/lib/PublicInbox/Mbox.pm
+++ b/lib/PublicInbox/Mbox.pm
@@ -213,7 +213,7 @@ sub results_cb {
                 }
                 # refill result set
                 my $srch = $ctx->{-inbox}->search(undef, $ctx) or return;
-                my $mset = $srch->query($ctx->{query}, $ctx->{qopts});
+                my $mset = $srch->mset($ctx->{query}, $ctx->{qopts});
                 my $size = $mset->size or return;
                 $ctx->{qopts}->{offset} += $size;
                 $ctx->{ids} = $srch->mset_to_artnums($mset);
@@ -235,7 +235,7 @@ sub results_thread_cb {
 
                 # refill result set
                 my $srch = $ctx->{-inbox}->search(undef, $ctx) or return;
-                my $mset = $srch->query($ctx->{query}, $ctx->{qopts});
+                my $mset = $srch->mset($ctx->{query}, $ctx->{qopts});
                 my $size = $mset->size or return;
                 $ctx->{qopts}->{offset} += $size;
                 $ctx->{ids} = $srch->mset_to_artnums($mset);
@@ -254,7 +254,7 @@ sub mbox_all {
 
         my $qopts = $ctx->{qopts} = { mset => 2 }; # order by docid
         $qopts->{thread} = 1 if $q->{t};
-        my $mset = $srch->query($q_string, $qopts);
+        my $mset = $srch->mset($q_string, $qopts);
         $qopts->{offset} = $mset->size or
                         return [404, [qw(Content-Type text/plain)],
                                 ["No results found\n"]];
diff --git a/lib/PublicInbox/Search.pm b/lib/PublicInbox/Search.pm
index 546884a9..cfa942b2 100644
--- a/lib/PublicInbox/Search.pm
+++ b/lib/PublicInbox/Search.pm
@@ -279,7 +279,7 @@ sub reopen {
 }
 
 # read-only
-sub query {
+sub mset {
         my ($self, $query_string, $opts) = @_;
         $opts ||= {};
         my $qp = $self->{qp} //= qparse_new($self);
@@ -346,17 +346,17 @@ sub _enquire_once { # retry_reopen callback
         if ($opts->{thread} && has_threadid($self)) {
                 $enquire->set_collapse_key(THREADID);
         }
+        $enquire->get_mset($opts->{offset} || 0, $opts->{limit} || 50);
+}
 
-        my $offset = $opts->{offset} || 0;
-        my $limit = $opts->{limit} || 50;
-        my $mset = $enquire->get_mset($offset, $limit);
-        return $mset if $opts->{mset};
+sub mset_to_smsg {
+        my ($self, $ibx, $mset) = @_;
         my $nshard = $self->{nshard} // 1;
         my $i = 0;
         my %order = map { mdocid($nshard, $_) => ++$i } $mset->items;
         my @msgs = sort {
                 $order{$a->{num}} <=> $order{$b->{num}}
-        } @{$self->{over_ro}->get_all(keys %order)};
+        } @{$ibx->over->get_all(keys %order)};
         wantarray ? ($mset->get_matches_estimated, \@msgs) : \@msgs;
 }
 
diff --git a/lib/PublicInbox/SearchView.pm b/lib/PublicInbox/SearchView.pm
index 892e8fda..c482f1c9 100644
--- a/lib/PublicInbox/SearchView.pm
+++ b/lib/PublicInbox/SearchView.pm
@@ -47,7 +47,6 @@ sub sres_top_html {
         my $opts = {
                 limit => $q->{l},
                 offset => $o,
-                mset => 1,
                 relevance => $q->{r},
                 thread => $q->{t},
                 asc => $asc,
@@ -55,7 +54,7 @@ sub sres_top_html {
         my ($mset, $total, $err, $html);
 retry:
         eval {
-                $mset = $srch->query($query, $opts);
+                $mset = $srch->mset($query, $opts);
                 $total = $mset->get_matches_estimated;
         };
         $err = $@;
diff --git a/lib/PublicInbox/SolverGit.pm b/lib/PublicInbox/SolverGit.pm
index ddf5fa16..ff8a4946 100644
--- a/lib/PublicInbox/SolverGit.pm
+++ b/lib/PublicInbox/SolverGit.pm
@@ -229,10 +229,9 @@ sub find_extract_diffs ($$$) {
                 }
         }
 
-        my $msgs = $srch->query($q, { relevance => 1 });
-
+        my $mset = $srch->mset($q, { relevance => 1 });
         my $diffs = [];
-        foreach my $smsg (@$msgs) {
+        for my $smsg (@{$srch->mset_to_smsg($ibx, $mset)}) {
                 my $eml = $ibx->smsg_eml($smsg) or next;
                 $eml->each_part(\&extract_diff,
                                 [$self, $diffs, $pre, $post, $ibx, $smsg], 1);