about summary refs log tree commit homepage
path: root/lib/PublicInbox/Search.pm
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2023-08-24 01:22:30 +0000
committerEric Wong <e@80x24.org>2023-08-24 07:47:47 +0000
commit45566a96cd813d266ea20bd291bb80c6374f5618 (patch)
tree851957e3cf829c49873bddb48fe2c217a1e1d1cb /lib/PublicInbox/Search.pm
parentd7d41f6ea7cfeb14fef5b7834b2f486eddb8195e (diff)
downloadpublic-inbox-45566a96cd813d266ea20bd291bb80c6374f5618.tar.gz
This will be useful for internal tooling and APIs.
Diffstat (limited to 'lib/PublicInbox/Search.pm')
-rw-r--r--lib/PublicInbox/Search.pm34
1 files changed, 19 insertions, 15 deletions
diff --git a/lib/PublicInbox/Search.pm b/lib/PublicInbox/Search.pm
index b2de3450..1559d9b3 100644
--- a/lib/PublicInbox/Search.pm
+++ b/lib/PublicInbox/Search.pm
@@ -202,28 +202,32 @@ sub xdir ($;$) {
         }
 }
 
-# returns all shards as separate Xapian::Database objects w/o combining
-sub xdb_shards_flat ($) {
+# returns shard directories as an array of strings, does not verify existence
+sub shard_dirs ($) {
         my ($self) = @_;
         my $xpfx = $self->{xpfx};
-        my (@xdb, $slow_phrase);
-        load_xapian();
-        $self->{qp_flags} //= $QP_FLAGS;
-        if ($xpfx =~ m!/xapian[0-9]+\z!) { # v1
-                @xdb = ($X{Database}->new($xpfx));
-                $self->{qp_flags} |= FLAG_PHRASE() if !-f "$xpfx/iamchert";
-        } else { # v2, eidx, cidx
+        if ($xpfx =~ m!/xapian[0-9]+\z!) { # v1 inbox
+                ($xpfx);
+        } else { # v2 inbox, eidx, cidx
                 opendir(my $dh, $xpfx) or return (); # not initialized yet
                 # We need numeric sorting so shard[0] is first for reading
                 # Xapian metadata, if needed
                 my $last = max(grep(/\A[0-9]+\z/, readdir($dh))) // return ();
-                @xdb = map {
-                        my $shard_dir = "$xpfx/$_";
-                        $slow_phrase ||= -f "$shard_dir/iamchert";
-                        $X{Database}->new($shard_dir);
-                } (0..$last);
-                $self->{qp_flags} |= FLAG_PHRASE() if !$slow_phrase;
+                map { "$xpfx/$_" } (0..$last);
         }
+}
+
+# returns all shards as separate Xapian::Database objects w/o combining
+sub xdb_shards_flat ($) {
+        my ($self) = @_;
+        load_xapian();
+        $self->{qp_flags} //= $QP_FLAGS;
+        my $slow_phrase;
+        my @xdb = map {
+                $slow_phrase ||= -f "$_/iamchert";
+                $X{Database}->new($_); # raises if missing
+        } shard_dirs($self);
+        $self->{qp_flags} |= FLAG_PHRASE() if !$slow_phrase;
         @xdb;
 }