]> Sergey Matveev's repositories - public-inbox.git/blobdiff - lib/PublicInbox/Search.pm
nntp: fix NEWNEWS command
[public-inbox.git] / lib / PublicInbox / Search.pm
index 67837f4f77300e6ef76333c623cb07eeca24ea30..df02e0b567587a728cd1d2d71511d96c92bb1a74 100644 (file)
@@ -1,5 +1,5 @@
-# Copyright (C) 2015 all contributors <meta@public-inbox.org>
-# License: AGPLv3 or later (https://www.gnu.org/licenses/agpl-3.0.txt)
+# Copyright (C) 2015-2018 all contributors <meta@public-inbox.org>
+# License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
 # based on notmuch, but with no concept of folders, files or flags
 #
 # Read-only search interface for use by the web and NNTP interfaces
@@ -75,6 +75,14 @@ my %prob_prefix = (
 
        q => 'XQUOT',
        nq => 'XNQ',
+       dfn => 'XDFN',
+       dfa => 'XDFA',
+       dfb => 'XDFB',
+       dfhh => 'XDFHH',
+       dfctx => 'XDFCTX',
+       dfpre => 'XDFPRE',
+       dfpost => 'XDFPOST',
+       dfblob => 'XDFPRE XDFPOST',
 
        # default:
        '' => 'XMID S A XNQ XQUOT XFN',
@@ -98,12 +106,16 @@ EOF
        'a:' => 'match within the To, Cc, and From headers',
        'tc:' => 'match within the To and Cc headers',
        'bs:' => 'match within the Subject and body',
+       'dfn:' => 'match filename from diff',
+       'dfa:' => 'match diff removed (-) lines',
+       'dfb:' => 'match diff added (+) lines',
+       'dfhh:' => 'match diff hunk header context (usually a function name)',
+       'dfctx:' => 'match diff context lines',
+       'dfpre:' => 'match pre-image git blob ID',
+       'dfpost:' => 'match post-image git blob ID',
+       'dfblob:' => 'match either pre or post-image git blob ID',
 );
 chomp @HELP;
-# TODO:
-# df (filenames from diff)
-# da (diff a/ removed lines)
-# db (diff b/ added lines)
 
 my $mail_query = Search::Xapian::Query->new('T' . 'mail');
 
@@ -269,6 +281,19 @@ sub query_xover {
        _do_enquire($self, $query, {num => 1, limit => 200, offset => $offset});
 }
 
+sub query_ts {
+       my ($self, $ts, $opts) = @_;
+       my $qp = $self->{qp_ts} ||= eval {
+               my $q = Search::Xapian::QueryParser->new;
+               $q->set_database($self->{xdb});
+               $q->add_valuerangeprocessor(
+                       Search::Xapian::NumberValueRangeProcessor->new(TS));
+               $q
+       };
+       my $query = $qp->parse_query($ts, QP_FLAGS);
+       _do_enquire($self, $query, $opts);
+}
+
 sub lookup_message {
        my ($self, $mid) = @_;
        $mid = mid_clean($mid);
@@ -288,7 +313,7 @@ sub lookup_mail { # no ghosts!
        my ($self, $mid) = @_;
        retry_reopen($self, sub {
                my $smsg = lookup_message($self, $mid) or return;
-               PublicInbox::SearchMsg->load_doc($smsg->{doc});
+               $smsg->load_expand;
        });
 }