-# Copyright (C) 2015-2021 all contributors <meta@public-inbox.org>
+# Copyright (C) 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
package PublicInbox::Search;
use strict;
+use v5.10.1;
use parent qw(Exporter);
our @EXPORT_OK = qw(retry_reopen int_val get_pct xap_terms);
use List::Util qw(max);
# compatibility with old indices (so don't change them it)
use constant {
TS => 0, # Received: in Unix time (IMAP INTERNALDATE, JMAP receivedAt)
- YYYYMMDD => 1, # Date: header for searching in the WWW UI
+ YYYYMMDD => 1, # redundant with DT below
DT => 2, # Date: YYYYMMDDHHMMSS (IMAP SENT*, JMAP sentAt)
# added for public-inbox 1.6.0+
dfpre => 'XDFPRE',
dfpost => 'XDFPOST',
dfblob => 'XDFPRE XDFPOST',
+ patchid => 'XDFID',
);
-my $non_quoted_body = 'XNQ XDFN XDFA XDFB XDFHH XDFCTX XDFPRE XDFPOST';
+my $non_quoted_body = 'XNQ XDFN XDFA XDFB XDFHH XDFCTX XDFPRE XDFPOST XDFID';
my %prob_prefix = (
# for mairix compatibility
s => 'S',
our @HELP = (
's:' => 'match within Subject e.g. s:"a quick brown fox"',
'd:' => <<EOF,
-date range as YYYYMMDD e.g. d:19931002..20101002
-Open-ended ranges such as d:19931002.. and d:..20101002
-are also supported
-EOF
- 'dt:' => <<EOF,
-date-time range as YYYYMMDDhhmmss (e.g. dt:19931002011000..19931002011200)
+match date-time range, git "approxidate" formats supported
+Open-ended ranges such as `d:last.week..' and
+`d:..2.days.ago' are supported
EOF
'b:' => 'match within message body, including text attachments',
'nq:' => 'match non-quoted text within message body',
'dfpre:' => 'match pre-image git blob ID',
'dfpost:' => 'match post-image git blob ID',
'dfblob:' => 'match either pre or post-image git blob ID',
+ 'patchid:' => "match `git patch-id --stable' output",
+ 'rt:' => <<EOF,
+match received time, like `d:' if sender's clock was correct
+EOF
);
chomp @HELP;
};
}
-# returns true if a future rescan is desired
-sub cleanup_shards {
- my ($self) = @_;
- return unless exists($self->{xdb});
- my $xpfx = $self->{xpfx};
- return reopen($self) if $xpfx =~ m!/xapian[0-9]+\z!; # true
- opendir(my $dh, $xpfx) or return warn("$xpfx gone: $!\n"); # true
- my $nr = grep(/\A[0-9]+\z/, readdir($dh)) or
- return warn("$xpfx has no shards\n"); # true
- return reopen($self) if $nr == ($self->{nshard} // -1);
- delete($self->{xdb});
- undef;
-}
-
sub new {
my ($class, $ibx) = @_;
ref $ibx or die "BUG: expected PublicInbox::Inbox object: $ibx";
my ($self, $cb, @arg) = @_;
for my $i (1..10) {
if (wantarray) {
- my @ret;
- eval { @ret = $cb->($self, @arg) };
+ my @ret = eval { $cb->($self, @arg) };
return @ret unless $@;
} else {
- my $ret;
- eval { $ret = $cb->($self, @arg) };
+ my $ret = eval { $cb->($self, @arg) };
return $ret unless $@;
}
# Exception: The revision being read has been discarded -
\@ret;
}
+# always returns a scalar value
sub int_val ($$) {
my ($doc, $col) = @_;
- my $val = $doc->get_value($col) or return; # undefined is '' in Xapian
+ my $val = $doc->get_value($col) or return undef; # undef is '' in Xapian
sortable_unserialise($val) + 0; # PV => IV conversion
}
wantarray ? sort(keys(%ret)) : \%ret;
}
+# get combined docid from over.num:
+# (not generic Xapian, only works with our sharding scheme)
+sub num2docid ($$) {
+ my ($self, $num) = @_;
+ my $nshard = $self->{nshard};
+ ($num - 1) * $nshard + $num % $nshard + 1;
+}
+
1;