YYYYMMDD => 1, # Date: header for searching in the WWW UI
DT => 2, # Date: YYYYMMDDHHMMSS
BYTES => 3, # IMAP RFC822.SIZE
+ UID => 4, # IMAP UID == NNTP article number == Xapian docid
# TODO
# REPLYCNT => 4, # IMAP ANSWERED
};
sub xdir ($;$) {
my ($self, $rdonly) = @_;
- if ($self->{ibx_ver} == 1) {
- "$self->{inboxdir}/public-inbox/xapian" . SCHEMA_VERSION;
- } else {
- my $dir = "$self->{inboxdir}/xap" . SCHEMA_VERSION;
- return $dir if $rdonly;
-
- my $shard = $self->{shard};
- defined $shard or die "shard not given";
- $dir .= "/$shard";
+ if ($rdonly || !defined($self->{shard})) {
+ $self->{xpfx};
+ } else { # v2 only:
+ "$self->{xpfx}/$self->{shard}";
}
}
my ($xdb, $slow_phrase);
my $qpf = \($self->{qp_flags} ||= $QP_FLAGS);
if ($self->{ibx_ver} >= 2) {
+ my $n = 0;
foreach my $shard (<$dir/*>) {
-d $shard && $shard =~ m!/[0-9]+\z! or next;
my $sub = $X{Database}->new($shard);
$xdb = $sub;
}
$slow_phrase ||= -f "$shard/iamchert";
+ ++$n;
}
+ $self->{nshard} = $n;
} else {
$slow_phrase = -f "$dir/iamchert";
$xdb = $X{Database}->new($dir);
$xdb;
}
+# v2 Xapian docids don't conflict, so they're identical to
+# NNTP article numbers and IMAP UIDs.
+# https://trac.xapian.org/wiki/FAQ/MultiDatabaseDocumentID
+sub mdocid {
+ my ($nshard, $mitem) = @_;
+ my $docid = $mitem->get_docid;
+ int(($docid - 1) / $nshard) + 1;
+}
+
sub xdb ($) {
my ($self) = @_;
$self->{xdb} ||= do {
};
}
+sub xpfx_init ($) {
+ my ($self) = @_;
+ if ($self->{ibx_ver} == 1) {
+ $self->{xpfx} .= '/public-inbox/xapian' . SCHEMA_VERSION;
+ } else {
+ $self->{xpfx} .= '/xap'.SCHEMA_VERSION;
+ }
+}
+
sub new {
my ($class, $ibx) = @_;
ref $ibx or die "BUG: expected PublicInbox::Inbox object: $ibx";
my $self = bless {
- inboxdir => $ibx->{inboxdir},
+ xpfx => $ibx->{inboxdir}, # for xpfx_init
altid => $ibx->{altid},
ibx_ver => $ibx->version,
}, $class;
+ xpfx_init($self);
my $dir = xdir($self, 1);
$self->{over_ro} = PublicInbox::Over->new("$dir/over.sqlite3");
$self;
$enquire->set_query($query);
$opts ||= {};
my $desc = !$opts->{asc};
- if (($opts->{mset} || 0) == 2) {
+ if (($opts->{mset} || 0) == 2) { # mset == 2: ORDER BY docid/UID
$enquire->set_docid_order($ENQ_ASCENDING);
$enquire->set_weighting_scheme($X{BoolWeight}->new);
} elsif ($opts->{relevance}) {
$qp->add_valuerangeprocessor($nvrp->new(YYYYMMDD, 'd:'));
$qp->add_valuerangeprocessor($nvrp->new(DT, 'dt:'));
+ # for IMAP, undocumented for WWW and may be split off go away
+ $qp->add_valuerangeprocessor($nvrp->new(BYTES, 'bytes:'));
+ $qp->add_valuerangeprocessor($nvrp->new(TS, 'ts:'));
+ $qp->add_valuerangeprocessor($nvrp->new(UID, 'uid:'));
+
while (my ($name, $prefix) = each %bool_pfx_external) {
$qp->add_boolean_prefix($name, $_) foreach split(/ /, $prefix);
}