sub xpfx { $all_pfx{$_[0]} }
-our %PFX2TERM_RMAP;
-my %meta_pfx = (mid => 1, thread => 1, path => 1);
-while (my ($k, $v) = each %all_pfx) {
- $PFX2TERM_RMAP{$v} = $k if $meta_pfx{$k};
-}
-
my $mail_query = Search::Xapian::Query->new(xpfx('type') . 'mail');
sub xdir {
use Date::Parse qw/str2time/;
use PublicInbox::MID qw/mid_clean/;
use PublicInbox::Address;
-our $PFX2TERM_RE = undef;
sub new {
my ($class, $mime) = @_;
defined $x ? $x : '';
}
-sub ensure_metadata {
- my ($self) = @_;
+sub _get_term_val ($$$) {
+ my ($self, $pfx, $re) = @_;
my $doc = $self->{doc};
my $end = $doc->termlist_end;
-
- unless (defined $PFX2TERM_RE) {
- my $or = join('|', keys %PublicInbox::Search::PFX2TERM_RMAP);
- $PFX2TERM_RE = qr/\A($or)/;
- }
-
- while (my ($pfx, $field) = each %PublicInbox::Search::PFX2TERM_RMAP) {
- # ideally we'd move this out of the loop:
- my $i = $doc->termlist_begin;
-
- $i->skip_to($pfx);
- if ($i != $end) {
- my $val = $i->get_termname;
-
- if ($val =~ s/$PFX2TERM_RE//o) {
- $self->{$field} = $val;
- }
- }
+ my $i = $doc->termlist_begin;
+ $i->skip_to($pfx);
+ if ($i != $end) {
+ my $val = $i->get_termname;
+ $val =~ s/$re// and return $val;
}
+ undef;
}
sub mid ($;$) {
} elsif (my $rv = $self->{mid}) {
$rv;
} else {
- $self->ensure_metadata; # needed for ghosts
- $self->{mid} ||= $self->_extract_mid;
+ $self->{mid} = _get_term_val($self, 'Q', qr/\AQ/) ||
+ $self->_extract_mid;
}
}
my ($self) = @_;
my $tid = $self->{thread};
return $tid if defined $tid;
- $self->ensure_metadata;
- $self->{thread};
+ $self->{thread} = _get_term_val($self, 'G', qr/\AG/); # *G*roup
}
sub path {
my ($self) = @_;
my $path = $self->{path};
return $path if defined $path;
- $self->ensure_metadata;
- $self->{path};
+ $self->{path} = _get_term_val($self, 'XPATH', qr/\AXPATH/); # path
}
1;
my $found = $ro->lookup_message('<root@s>');
ok($found, "message found");
is($root_id, $found->{doc_id}, 'doc_id set correctly');
- $found->ensure_metadata;
is($found->mid, 'root@s', 'mid set correctly');
ok(int($found->thread_id) > 0, 'thread_id is an integer');
body => "LOOP!\n"));
ok($doc_id > 0, "doc_id defined with circular reference");
my $smsg = $rw->lookup_message('circle@a');
- $smsg->ensure_metadata;
is($smsg->references, '', "no references created");
my $msg = PublicInbox::SearchMsg->load_doc($smsg->{doc});
is($s, $msg->subject, 'long subject not rewritten');