-sub lookup_mail { # no ghosts!
- my ($self, $mid) = @_;
- my $smsg = lookup_message($self, $mid) or return;
- PublicInbox::SearchMsg->load_doc($smsg->{doc});
-}
-
-sub find_unique_doc_id {
- my ($self, $term, $value) = @_;
-
- my ($begin, $end) = $self->find_doc_ids($term, $value);
-
- return undef if $begin->equal($end); # not found
-
- my $rv = $begin->get_docid;
-
- # sanity check
- $begin->inc;
- $begin->equal($end) or die "Term '$term:$value' is not unique\n";
- $rv;
-}
-
-# returns begin and end PostingIterator
-sub find_doc_ids {
- my ($self, $term, $value) = @_;
-
- $self->find_doc_ids_for_term(xpfx($term) . $value);
+sub lookup_article {
+ my ($self, $num) = @_;
+ my $term = 'XNUM'.$num;
+ my $db = $self->{xdb};
+ retry_reopen($self, sub {
+ my $head = $db->postlist_begin($term);
+ my $tail = $db->postlist_end($term);
+ return if $head->equal($tail);
+ my $doc_id = $head->get_docid;
+ return unless defined $doc_id;
+ $head->inc;
+ if ($head->nequal($tail)) {
+ warn "article #$num is not unique\n";
+ }
+ # raises on error:
+ my $doc = $db->get_document($doc_id);
+ my $smsg = PublicInbox::SearchMsg->wrap($doc);
+ $smsg->{doc_id} = $doc_id;
+ $smsg->load_expand;
+ });