]> Sergey Matveev's repositories - public-inbox.git/blobdiff - lib/PublicInbox/SearchIdx.pm
lei import: vivify external-only messages
[public-inbox.git] / lib / PublicInbox / SearchIdx.pm
index e2a1a678927176c2ec17551ce0c65c7f54f310ad..3f9331211ad8e5388ab175979d4b2ec3eaa12368 100644 (file)
@@ -11,6 +11,7 @@ use strict;
 use v5.10.1;
 use parent qw(PublicInbox::Search PublicInbox::Lock Exporter);
 use PublicInbox::Eml;
+use PublicInbox::Search qw(xap_terms);
 use PublicInbox::InboxWritable;
 use PublicInbox::MID qw(mids_for_index mids);
 use PublicInbox::MsgIter;
@@ -34,6 +35,7 @@ use constant DEBUG => !!$ENV{DEBUG};
 my $xapianlevels = qr/\A(?:full|medium)\z/;
 my $hex = '[a-f0-9]';
 my $OID = $hex .'{40,}';
+my @VMD_MAP = (kw => 'K', label => 'L');
 our $INDEXLEVELS = qr/\A(?:full|medium|basic)\z/;
 
 sub new {
@@ -428,7 +430,15 @@ sub eml2doc ($$$;$) {
 sub add_xapian ($$$$) {
        my ($self, $eml, $smsg, $mids) = @_;
        begin_txn_lazy($self);
+       my $merge_vmd = delete $smsg->{-merge_vmd};
        my $doc = eml2doc($self, $eml, $smsg, $mids);
+       if (my $old = $merge_vmd ? _get_doc($self, $smsg->{num}) : undef) {
+               my @x = @VMD_MAP;
+               while (my ($field, $pfx) = splice(@x, 0, 2)) {
+                       my $vals = xap_terms($pfx, $old);
+                       $doc->add_boolean_term($pfx.$_) for keys %$vals;
+               }
+       }
        $self->{xdb}->replace_document($smsg->{num}, $doc);
 }
 
@@ -494,7 +504,10 @@ sub add_eidx_info {
        begin_txn_lazy($self);
        my $doc = _get_doc($self, $docid) or return;
        term_generator($self)->set_document($doc);
+
+       # '.' is special for lei_store
        $doc->add_boolean_term('O'.$eidx_key) if $eidx_key ne '.';
+
        index_list_id($self, $doc, $eml);
        $self->{xdb}->replace_document($docid, $doc);
 }
@@ -528,8 +541,6 @@ sub remove_eidx_info {
        $self->{xdb}->replace_document($docid, $doc);
 }
 
-my @VMD_MAP = (kw => 'K', label => 'L');
-
 sub set_vmd {
        my ($self, $docid, $vmd) = @_;
        begin_txn_lazy($self);