about summary refs log tree commit homepage
path: root/lib/PublicInbox/Search.pm
diff options
context:
space:
mode:
authorEric Wong (Contractor, The Linux Foundation) <e@80x24.org>2018-03-03 18:47:47 +0000
committerEric Wong (Contractor, The Linux Foundation) <e@80x24.org>2018-03-03 18:49:17 +0000
commitfa3283debd81490ac1d5e0895fc2d8968e1f110b (patch)
tree8d280acf37198ad3ba8ea50681a7923f071a72a4 /lib/PublicInbox/Search.pm
parentae68bf5da734189549bbac3a525845a58e45d77f (diff)
downloadpublic-inbox-fa3283debd81490ac1d5e0895fc2d8968e1f110b.tar.gz
Since Message-IDs are no longer unique within Xapian
(but are within the SQLite Msgmap); favor NNTP article
numbers for internal lookups.  This will prevent us
from finding the "wrong" internal Message-ID.
Diffstat (limited to 'lib/PublicInbox/Search.pm')
-rw-r--r--lib/PublicInbox/Search.pm21
1 files changed, 21 insertions, 0 deletions
diff --git a/lib/PublicInbox/Search.pm b/lib/PublicInbox/Search.pm
index a1c423c8..802984b0 100644
--- a/lib/PublicInbox/Search.pm
+++ b/lib/PublicInbox/Search.pm
@@ -372,6 +372,27 @@ sub lookup_mail { # no ghosts!
         });
 }
 
+sub lookup_article {
+        my ($self, $num) = @_;
+        my $term = 'XNUM'.$num;
+        my $smsg;
+        eval {
+                retry_reopen($self, sub {
+                        my $db = $self->{skel} || $self->{xdb};
+                        my $head = $db->postlist_begin($term);
+                        return if $head == $db->postlist_end($term);
+                        my $doc_id = $head->get_docid;
+                        return unless defined $doc_id;
+                        # raises on error:
+                        my $doc = $db->get_document($doc_id);
+                        $smsg = PublicInbox::SearchMsg->wrap($doc);
+                        $smsg->load_expand;
+                        $smsg->{doc_id} = $doc_id;
+                });
+        };
+        $smsg;
+}
+
 sub each_smsg_by_mid {
         my ($self, $mid, $cb) = @_;
         my $xdb = $self->{xdb};