- 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) = @_;
- # XXX retry_reopen isn't necessary for V2Writable, but the PSGI
- # interface will need it...
- my $db = $self->{skel} || $self->{xdb};
- my $term = 'Q' . $mid;
- my $head = $db->postlist_begin($term);
- my $tail = $db->postlist_end($term);
- return ($head, $tail, $db) if wantarray;
- for (; $head->nequal($tail); $head->inc) {
- my $doc_id = $head->get_docid;
- my $doc = $db->get_document($doc_id);
- my $smsg = PublicInbox::SearchMsg->wrap($doc, $mid);
- $smsg->{doc_id} = $doc_id;
- $cb->($smsg) or return;
- }
-}
-
-sub find_unique_doc_id {
- my ($self, $termval) = @_;
-
- my ($begin, $end) = $self->find_doc_ids($termval);
-
- return undef if $begin->equal($end); # not found
-
- my $rv = $begin->get_docid;
-
- # sanity check
- $begin->inc;
- $begin->equal($end) or die "Term '$termval' is not unique\n";
- $rv;
-}
-
-# returns begin and end PostingIterator
-sub find_doc_ids {
- my ($self, $termval) = @_;
- my $db = $self->{xdb};
-
- ($db->postlist_begin($termval), $db->postlist_end($termval));