-sub num_range_processor {
- $_[0]->{nrp} ||= Search::Xapian::NumberValueRangeProcessor->new(NUM);
-}
-
-# only used for NNTP server
-sub query_xover {
- my ($self, $beg, $end, $offset) = @_;
- my $qp = Search::Xapian::QueryParser->new;
- $qp->set_database($self->{xdb});
- $qp->add_valuerangeprocessor($self->num_range_processor);
- my $query = $qp->parse_query("$beg..$end", QP_FLAGS);
-
- _do_enquire($self, $query, {num => 1, limit => 200, offset => $offset});
-}
-
-sub lookup_message {
- my ($self, $mid) = @_;
- $mid = mid_clean($mid);
-
- my $doc_id = $self->find_first_doc_id('XMID' . $mid);
- my $smsg;
- if (defined $doc_id) {
- # raises on error:
- my $doc = $self->{xdb}->get_document($doc_id);
- $smsg = PublicInbox::SearchMsg->wrap($doc, $mid);
- $smsg->{doc_id} = $doc_id;
- }
- $smsg;
-}
-
-sub lookup_mail { # no ghosts!
- my ($self, $mid) = @_;
- retry_reopen($self, sub {
- my $smsg = lookup_message($self, $mid) or return;
- $smsg->load_expand;
- });
-}
-
-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));
-}
-
-sub find_first_doc_id {
- my ($self, $termval) = @_;
-
- my ($begin, $end) = $self->find_doc_ids($termval);
-
- return undef if $begin->equal($end); # not found
-
- $begin->get_docid;
-}
-
-# normalize subjects so they are suitable as pathnames for URLs
-# XXX: consider for removal
-sub subject_path {
- my $subj = pop;
- $subj = subject_normalized($subj);
- $subj =~ s![^a-zA-Z0-9_\.~/\-]+!_!g;
- lc($subj);
-}
-
-sub subject_normalized {
- my $subj = pop;
- $subj =~ s/\A\s+//s; # no leading space
- $subj =~ s/\s+\z//s; # no trailing space
- $subj =~ s/\s+/ /gs; # no redundant spaces
- $subj =~ s/\.+\z//; # no trailing '.'
- $subj =~ s/$REPLY_RE//igo; # remove reply prefix
- $subj;
-}
-
-sub enquire {
- my ($self) = @_;
- $self->{enquire} ||= Search::Xapian::Enquire->new($self->{xdb});
-}
-