X-Git-Url: http://www.git.stargrave.org/?a=blobdiff_plain;f=lib%2FPublicInbox%2FSearchIdx.pm;h=f9b40b0db5a9968c0bdf11de0dfffa628ae08d95;hb=3348ad4b3b1a0865ee58a902953165ea0f4aa4bd;hp=4256263124b74fdbb21f22311e00a569ec3763b9;hpb=936670cb83971bf250571a7dd9b0a0a0b33babd8;p=public-inbox.git diff --git a/lib/PublicInbox/SearchIdx.pm b/lib/PublicInbox/SearchIdx.pm index 42562631..f9b40b0d 100644 --- a/lib/PublicInbox/SearchIdx.pm +++ b/lib/PublicInbox/SearchIdx.pm @@ -12,7 +12,7 @@ use warnings; use base qw(PublicInbox::Search PublicInbox::Lock); use PublicInbox::MIME; use PublicInbox::InboxWritable; -use PublicInbox::MID qw/mid_clean id_compress mid_mime mids references/; +use PublicInbox::MID qw/mid_clean id_compress mid_mime mids/; use PublicInbox::MsgIter; use Carp qw(croak); use POSIX qw(strftime); @@ -273,23 +273,12 @@ sub add_message { my $smsg = PublicInbox::SearchMsg->new($mime); my $doc = $smsg->{doc}; my $subj = $smsg->subject; - my $xpath; - if ($subj ne '') { - $xpath = $self->subject_path($subj); - $xpath = id_compress($xpath); - } - - $smsg->{lines} = $mime->body_raw =~ tr!\n!\n!; - defined $bytes or $bytes = length($mime->as_string); - $smsg->{bytes} = $bytes; - add_val($doc, PublicInbox::Search::TS(), $smsg->ts); my @ds = gmtime($smsg->ds); my $yyyymmdd = strftime('%Y%m%d', @ds); add_val($doc, PublicInbox::Search::YYYYMMDD(), $yyyymmdd); my $dt = strftime('%Y%m%d%H%M%S', @ds); add_val($doc, PublicInbox::Search::DT(), $dt); - my @vals = ($smsg->{ts}, $smsg->{ds}); my $tg = $self->term_generator; @@ -338,12 +327,11 @@ sub add_message { index_body($tg, \@orig, $doc) if @orig; }); - # populates smsg->references for smsg->to_doc_data - my $refs = parse_references($smsg, $mid0, $mids); - my $data = $smsg->to_doc_data($oid, $mid0); foreach my $mid (@$mids) { $tg->index_text($mid, 1, 'XM'); } + $smsg->{to} = $smsg->{cc} = ''; + my $data = $smsg->to_doc_data($oid, $mid0); $doc->set_data($data); if (my $altid = $self->{-altid}) { foreach my $alt (@$altid) { @@ -356,15 +344,11 @@ sub add_message { } } - $self->delete_article($num) if defined $num; # for reindexing - - utf8::encode($data); - $data = compress($data); - push @vals, $num, $mids, $refs, $xpath, $data; - $self->{over}->add_over(\@vals); + if (my $over = $self->{over}) { + $over->add_overview($mime, $bytes, $num, $oid, $mid0); + } $doc->add_boolean_term('Q' . $_) foreach @$mids; - $doc->add_boolean_term('XNUM' . $num) if defined $num; - $doc_id = $self->{xdb}->add_document($doc); + $self->{xdb}->replace_document($doc_id = $num, $doc); }; if ($@) { @@ -416,21 +400,13 @@ sub remove_message { } } -sub delete_article { - my ($self, $num) = @_; - my $ndel = 0; - batch_do($self, 'XNUM' . $num, sub { - my ($ids) = @_; - $ndel += scalar @$ids; - $self->{xdb}->delete_document($_) for @$ids; - }); -} - # MID is a hint in V2 sub remove_by_oid { my ($self, $oid, $mid) = @_; my $db = $self->{xdb}; + $self->{over}->remove_oid($oid, $mid) if $self->{over}; + # XXX careful, we cannot use batch_do here since we conditionally # delete documents based on other factors, so we cannot call # find_doc_ids twice. @@ -440,7 +416,6 @@ sub remove_by_oid { # there is only ONE element in @delete unless we # have bugs in our v2writable deduplication check my @delete; - my @over_del; for (; $head != $tail; $head->inc) { my $docid = $head->get_docid; my $doc = $db->get_document($docid); @@ -448,11 +423,9 @@ sub remove_by_oid { $smsg->load_expand; if ($smsg->{blob} eq $oid) { push(@delete, $docid); - push(@over_del, $smsg->num); } } $db->delete_document($_) foreach @delete; - $self->{over}->remove_oid($oid, $mid); scalar(@delete); } @@ -468,29 +441,6 @@ sub term_generator { # write-only $self->{term_generator} = $tg; } -sub parse_references ($$$) { - my ($smsg, $mid0, $mids) = @_; - my $mime = $smsg->{mime}; - my $hdr = $mime->header_obj; - my $refs = references($hdr); - push(@$refs, @$mids) if scalar(@$mids) > 1; - return $refs if scalar(@$refs) == 0; - - # prevent circular references here: - my %seen = ( $mid0 => 1 ); - my @keep; - foreach my $ref (@$refs) { - if (length($ref) > PublicInbox::MID::MAX_MID_SIZE) { - warn "References: <$ref> too long, ignoring\n"; - next; - } - next if $seen{$ref}++; - push @keep, $ref; - } - $smsg->{references} = '<'.join('> <', @keep).'>' if @keep; - \@keep; -} - sub index_git_blob_id { my ($doc, $pfx, $objid) = @_; @@ -618,7 +568,7 @@ sub _git_log { --raw -r --no-abbrev/, $range); } -# indexes all unindexed messages +# indexes all unindexed messages (v1 only) sub _index_sync { my ($self, $opts) = @_; my $tip = $opts->{ref} || 'HEAD'; @@ -749,7 +699,7 @@ sub begin_txn_lazy { my ($self) = @_; return if $self->{txn}; my $xdb = $self->{xdb} || $self->_xdb_acquire; - $self->{over}->begin_lazy; + $self->{over}->begin_lazy if $self->{over}; $xdb->begin_transaction; $self->{txn} = 1; $xdb; @@ -759,7 +709,7 @@ sub commit_txn_lazy { my ($self) = @_; delete $self->{txn} or return; $self->{xdb}->commit_transaction; - $self->{over}->commit_lazy; + $self->{over}->commit_lazy if $self->{over}; } sub worker_done {