# SCHEMA_VERSION history
# 0 - initial
# 1 - subject_path is lower-cased
- SCHEMA_VERSION => 1,
+ # 2 - subject_path is mid_compressed in the index, only
+ # 3 - message-ID is compressed if it includes '%' (hack!)
+ SCHEMA_VERSION => 3,
LANG => 'english',
QP_FLAGS => FLAG_PHRASE|FLAG_BOOLEAN|FLAG_LOVEHATE|FLAG_WILDCARD,
};
if ($writable) { # not used by the WWW interface
require Search::Xapian::WritableDatabase;
- require File::Path;
- File::Path::mkpath($dir);
- $db = Search::Xapian::WritableDatabase->new($dir,
- Search::Xapian::DB_CREATE_OR_OPEN);
+ my $flag = Search::Xapian::DB_OPEN;
+ if ($writable == 1) {
+ require File::Path;
+ File::Path::mkpath($dir);
+ $flag = Search::Xapian::DB_CREATE_OR_OPEN;
+ }
+ $db = Search::Xapian::WritableDatabase->new($dir, $flag);
} else {
$db = Search::Xapian::Database->new($dir);
}
my $db = $self->{xdb};
my $doc_id;
- my $mid = mid_clean($mime->header('Message-ID'));
+ my $mid = mid_clean($mime->header_obj->header_raw('Message-ID'));
$mid = mid_compressed($mid);
my $was_ghost = 0;
my $ct_msg = $mime->header('Content-Type') || 'text/plain';
my $enc_msg = PublicInbox::View::enc_for($ct_msg);
- $db->begin_transaction;
eval {
my $smsg = $self->lookup_message($mid);
my $doc;
$doc->add_term(xpfx('subject') . $subj);
my $path = subject_path($subj);
- $doc->add_term(xpfx('path') . $path);
+ $doc->add_term(xpfx('path') . mid_compressed($path));
}
my $from = $smsg->from_name;
if ($@) {
warn "failed to index message <$mid>: $@\n";
- $db->cancel_transaction;
- } else {
- $db->commit_transaction;
+ return undef;
}
$doc_id;
}
$mid = mid_clean($mid);
$mid = mid_compressed($mid);
- $db->begin_transaction;
eval {
$doc_id = $self->find_unique_doc_id('mid', $mid);
$db->delete_document($doc_id) if defined $doc_id;
if ($@) {
warn "failed to remove message <$mid>: $@\n";
- $db->cancel_transaction;
- } else {
- $db->commit_transaction;
+ return undef;
}
$doc_id;
}
sub get_subject_path {
my ($self, $path, $opts) = @_;
- my $query = $self->qp->parse_query("path:$path", 0);
+ my $query = $self->qp->parse_query("path:".mid_compressed($path), 0);
$self->do_enquire($query);
}
-# given a message ID, get replies to a message
-sub get_replies {
+# given a message ID, get followups to a message
+sub get_followups {
my ($self, $mid, $opts) = @_;
$mid = mid_clean($mid);
$mid = mid_compressed($mid);
return { count => 0, msgs => [] } unless $smsg;
my $qp = $self->qp;
my $qtid = $qp->parse_query('thread:'.$smsg->thread_id);
- my $qsub = $qp->parse_query('path:'.$smsg->path);
+ my $qsub = $qp->parse_query('path:'.mid_compressed($smsg->path));
my $query = Search::Xapian::Query->new(OP_OR, $qtid, $qsub);
$self->do_enquire($query);
}
my $doc = $smsg->{doc};
my $mid = mid_compressed($smsg->mid);
my $mime = $smsg->mime;
- my $refs = $mime->header('References');
+ my $refs = $mime->header_obj->header_raw('References');
my @refs = $refs ? ($refs =~ /<([^>]+)>/g) : ();
- my $irt = $mime->header('In-Reply-To');
+ my $irt = $mime->header_obj->header_raw('In-Reply-To');
if ($irt) {
if ($irt =~ /<([^>]+)>/) {
$irt = $1;
sub unindex_blob {
my ($self, $git, $blob) = @_;
my $mime = do_cat_mail($git, $blob) or return;
- my $mid = $mime->header('Message-ID');
+ my $mid = $mime->header_obj->header_raw('Message-ID');
eval { $self->remove_message($mid) } if defined $mid;
warn "W: unindex_blob $blob: $@\n" if $@;
}
# indexes all unindexed messages
sub index_sync {
- my ($self, $git) = @_;
+ my ($self) = @_;
+ require PublicInbox::GitCatFile;
my $db = $self->{xdb};
- my $latest = $db->get_metadata('last_commit');
- my $range = length $latest ? "$latest..HEAD" : 'HEAD';
- $latest = undef;
-
my $hex = '[a-f0-9]';
my $h40 = $hex .'{40}';
my $addmsg = qr!^:000000 100644 \S+ ($h40) A\t${hex}{2}/${hex}{38}$!;
my $delmsg = qr!^:100644 000000 ($h40) \S+ D\t${hex}{2}/${hex}{38}$!;
- # get indexed messages
- my @cmd = ('git', "--git-dir=$git->{git_dir}", "log",
- qw/--reverse --no-notes --no-color --raw -r --no-abbrev/,
- $range);
-
- my $pid = open(my $log, '-|', @cmd) or
- die('open` '.join(' ', @cmd) . " pipe failed: $!\n");
- my $last;
- while (my $line = <$log>) {
- if ($line =~ /$addmsg/o) {
- $self->index_blob($git, $1);
- } elsif ($line =~ /$delmsg/o) {
- $self->unindex_blob($git, $1);
- } elsif ($line =~ /^commit ($h40)/o) {
- my $commit = $1;
- if (defined $latest) {
- $db->set_metadata('last_commit', $latest)
+ $db->begin_transaction;
+ eval {
+ my $git = PublicInbox::GitCatFile->new($self->{git_dir});
+
+ my $latest = $db->get_metadata('last_commit');
+ my $range = length $latest ? "$latest..HEAD" : 'HEAD';
+ $latest = undef;
+
+ # get indexed messages
+ my @cmd = ('git', "--git-dir=$self->{git_dir}", "log",
+ qw/--reverse --no-notes --no-color --raw -r
+ --no-abbrev/, $range);
+ my $pid = open(my $log, '-|', @cmd) or
+ die('open` '.join(' ', @cmd) . " pipe failed: $!\n");
+
+ while (my $line = <$log>) {
+ if ($line =~ /$addmsg/o) {
+ $self->index_blob($git, $1);
+ } elsif ($line =~ /$delmsg/o) {
+ $self->unindex_blob($git, $1);
+ } elsif ($line =~ /^commit ($h40)/o) {
+ $latest = $1;
}
- $latest = $commit;
}
+ close $log;
+ $db->set_metadata('last_commit', $latest) if defined $latest;
+ };
+ if ($@) {
+ warn "indexing failed: $@\n";
+ $db->cancel_transaction;
+ } else {
+ $db->commit_transaction;
}
- close $log;
- $db->set_metadata('last_commit', $latest) if defined $latest;
}
1;