about summary refs log tree commit homepage
path: root/lib/PublicInbox
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2021-10-02 08:16:22 +0000
committerEric Wong <e@80x24.org>2021-10-02 20:09:22 +0000
commit502297d2cda95376b38e7d510f1d34fe89a3ec0e (patch)
tree92282db59ecb327091d740000664ad7c333a6309 /lib/PublicInbox
parent3826b39b6433ecec96a0230ae4602b7c819fde66 (diff)
downloadpublic-inbox-502297d2cda95376b38e7d510f1d34fe89a3ec0e.tar.gz
This fixes inspect for uninitialized instances, and adds Xapian
("xdoc") output if available.

Reported-by: Konstantin Ryabitsev <konstantin@linuxfoundation.org>
Message-ID: <20211001204943.l4yl6xvc45c5eapz@meerkat.local>
Diffstat (limited to 'lib/PublicInbox')
-rw-r--r--lib/PublicInbox/LeiInspect.pm59
1 files changed, 33 insertions, 26 deletions
diff --git a/lib/PublicInbox/LeiInspect.pm b/lib/PublicInbox/LeiInspect.pm
index f18e31c5..590dfdab 100644
--- a/lib/PublicInbox/LeiInspect.pm
+++ b/lib/PublicInbox/LeiInspect.pm
@@ -78,22 +78,9 @@ sub inspect_sync_folder ($$) {
         $ent
 }
 
-sub inspect_docid ($$;$) {
-        my ($lei, $docid, $ent) = @_;
-        require PublicInbox::Search;
-        $ent //= {};
-        my $xdb;
-        if ($xdb = delete $ent->{xdb}) { # from inspect_num
-        } elsif (defined(my $dir = $lei->{opt}->{dir})) {
-                no warnings 'once';
-                $xdb = $PublicInbox::Search::X{Database}->new($dir);
-        } else {
-                $xdb = $lei->{lse}->xdb;
-        }
-        $xdb or return $lei->fail('no Xapian DB');
-        my $doc = $xdb->get_document($docid); # raises
+sub _inspect_doc ($$) {
+        my ($ent, $doc) = @_;
         my $data = $doc->get_data;
-        $ent->{docid} = $docid;
         $ent->{data_length} = length($data);
         $ent->{description} = $doc->get_description;
         $ent->{$_} = $doc->$_ for (qw(termlist_count values_count));
@@ -119,6 +106,24 @@ sub inspect_docid ($$;$) {
         $ent;
 }
 
+sub inspect_docid ($$;$) {
+        my ($lei, $docid, $ent) = @_;
+        require PublicInbox::Search;
+        $ent //= {};
+        my $xdb;
+        if ($xdb = delete $ent->{xdb}) { # from inspect_num
+        } elsif (defined(my $dir = $lei->{opt}->{dir})) {
+                no warnings 'once';
+                $xdb = $PublicInbox::Search::X{Database}->new($dir);
+        } elsif ($lei->{lse}) {
+                $xdb = $lei->{lse}->xdb;
+        }
+        $xdb or return $lei->fail('no Xapian DB');
+        my $doc = $xdb->get_document($docid); # raises
+        $ent->{docid} = $docid;
+        _inspect_doc($ent, $doc);
+}
+
 sub dir2ibx ($$) {
         my ($lei, $dir) = @_;
         if (-f "$dir/ei.lock") {
@@ -138,11 +143,9 @@ sub inspect_num ($$) {
         my $ent = { num => $num };
         if (defined(my $dir = $lei->{opt}->{dir})) {
                 $ibx = dir2ibx($lei, $dir) or return;
-                if ($ent->{xdb} = $ibx->xdb) {
-                        my $num2docid = $lei->{lse}->can('num2docid');
-                        $docid = $num2docid->($ibx, $num);
-                }
-        } else {
+                $ent->{xdb} = $ibx->xdb and # for inspect_docid
+                        $docid = PublicInbox::LeiSearch::num2docid($ibx, $num);
+        } elsif ($lei->{lse}) {
                 $ibx = $lei->{lse};
                 $lei->{lse}->xdb; # set {nshard} for num2docid
                 $docid = $lei->{lse}->num2docid($num);
@@ -156,16 +159,12 @@ sub inspect_num ($$) {
 
 sub inspect_mid ($$) {
         my ($lei, $mid) = @_;
-        my ($ibx, $over);
+        my $ibx;
         my $ent = { mid => $mid };
         if (defined(my $dir = $lei->{opt}->{dir})) {
-                my $num2docid = $lei->{lse}->can('num mid => [ $mid ] 2docid');
-                $ibx = dir2ibx($lei, $dir) or return;
-                # $ent->{xdb} = $ibx->xdb //
-                        # return $lei->fail("no Xapian DB for $dir");
+                $ibx = dir2ibx($lei, $dir)
         } else {
                 $ibx = $lei->{lse};
-                $lei->{lse}->xdb; # set {nshard} for num2docid
         }
         if ($ibx && $ibx->over) {
                 my ($id, $prev);
@@ -173,6 +172,14 @@ sub inspect_mid ($$) {
                         push @{$ent->{smsg}}, _json_prep($smsg);
                 }
         }
+        if ($ibx && $ibx->search) {
+                my $mset = $ibx->search->mset(qq{mid:"$mid"});
+                for (sort { $a->get_docid <=> $b->get_docid } $mset->items) {
+                        my $tmp = { docid => $_->get_docid };
+                        _inspect_doc($tmp, $_->get_document);
+                        push @{$ent->{xdoc}}, $tmp;
+                }
+        }
         $ent;
 }