use PublicInbox::MID qw/mid_clean id_compress mid_mime/;
use PublicInbox::MsgIter;
use Carp qw(croak);
+use POSIX qw(strftime);
require PublicInbox::Git;
*xpfx = *PublicInbox::Search::xpfx;
};
sub new {
- my ($class, $git_dir, $creat) = @_;
+ my ($class, $inbox, $creat) = @_;
+ my $git_dir = $inbox;
+ my $altid;
+ if (ref $inbox) {
+ $git_dir = $inbox->{mainrepo};
+ $altid = $inbox->{altid};
+ if ($altid) {
+ require PublicInbox::AltId;
+ $altid = [ map {
+ PublicInbox::AltId->new($inbox, $_);
+ } @$altid ];
+ }
+ }
require Search::Xapian::WritableDatabase;
- my $self = bless { git_dir => $git_dir }, $class;
+ my $self = bless { git_dir => $git_dir, -altid => $altid }, $class;
my $perm = $self->_git_config_perm;
my $umask = _umask_for($perm);
$self->{umask} = $umask;
$doc->add_term(xpfx('path') . id_compress($path));
}
- add_val($doc, &PublicInbox::Search::TS, $smsg->ts);
+ my $ts = $smsg->ts;
+ add_val($doc, &PublicInbox::Search::TS, $ts);
defined($num) and
add_val($doc, &PublicInbox::Search::NUM, $num);
add_val($doc, &PublicInbox::Search::LINES,
$mime->body_raw =~ tr!\n!\n!);
+ my $yyyymmdd = strftime('%Y%m%d', gmtime($ts));
+ $doc->add_value(&PublicInbox::Search::YYYYMMDD, $yyyymmdd);
+
my $tg = $self->term_generator;
$tg->set_document($doc);
});
link_message($self, $smsg, $old_tid);
+ $tg->index_text($mid, 1);
$doc->set_data($smsg->to_doc_data($blob));
+
+ if (my $altid = $self->{-altid}) {
+ foreach my $alt (@$altid) {
+ my $id = $alt->mid2alt($mid);
+ next unless defined $id;
+ $doc->add_term($alt->{xprefix} . $id);
+ }
+ }
if (defined $doc_id) {
$db->replace_document($doc_id, $doc);
} else {
my $mm = _msgmap_init($self);
my $dbh = $mm->{dbh} if $mm;
+ my $mm_only;
my $cb = sub {
my ($commit, $more) = @_;
if ($dbh) {
$mm->last_commit($commit) if $commit;
$dbh->commit;
}
- $xdb->set_metadata($mkey, $commit) if $mkey && $commit;
- $xdb->commit_transaction;
- $xdb = _xdb_release($self);
+ if (!$mm_only) {
+ $xdb->set_metadata($mkey, $commit) if $mkey && $commit;
+ $xdb->commit_transaction;
+ $xdb = _xdb_release($self);
+ }
# let another process do some work... <
if ($more) {
- $xdb = _xdb_acquire($self);
- $xdb->begin_transaction;
+ if (!$mm_only) {
+ $xdb = _xdb_acquire($self);
+ $xdb->begin_transaction;
+ }
$dbh->begin_work if $dbh;
}
};
my $mkey_prev = $mkey;
$mkey = undef; # ignore xapian, for now
my $mlog = _git_log($self, $r);
+ $mm_only = 1;
rlog($self, $mlog, *index_mm, *unindex_mm, $cb);
- $mlog = undef;
+ $mm_only = $mlog = undef;
# now deal with Xapian
$mkey = $mkey_prev;
$dbh = undef;
- $xdb = _xdb_acquire($self);
- $xdb->begin_transaction;
rlog($self, $xlog, *index_mm2, *unindex_mm2, $cb);
}
} else {