]> Sergey Matveev's repositories - public-inbox.git/blobdiff - lib/PublicInbox/Search.pm
nntp: fix NEWNEWS command
[public-inbox.git] / lib / PublicInbox / Search.pm
index a1c423c892d5632fe0027f474015798c1cc11b11..4dc274723d6ca8e34ca19821256308d47ea7058d 100644 (file)
@@ -330,6 +330,20 @@ sub query_xover {
        _do_enquire($self, $query, $opts);
 }
 
+sub query_ts {
+       my ($self, $ts, $opts) = @_;
+       my $qp = $self->{qp_ts} ||= eval {
+               my $q = Search::Xapian::QueryParser->new;
+               $q->set_database($self->{skel} || $self->{xdb});
+               $q->add_valuerangeprocessor(
+                       Search::Xapian::NumberValueRangeProcessor->new(TS));
+               $q
+       };
+       my $query = $qp->parse_query($ts, QP_FLAGS);
+       $opts->{enquire} = enquire_skel($self);
+       _do_enquire($self, $query, $opts);
+}
+
 sub lookup_skeleton {
        my ($self, $mid) = @_;
        my $skel = $self->{skel} or return lookup_message($self, $mid);
@@ -372,6 +386,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};