]> Sergey Matveev's repositories - public-inbox.git/blobdiff - lib/PublicInbox/SearchIdx.pm
search: reduce columns stored in Xapian
[public-inbox.git] / lib / PublicInbox / SearchIdx.pm
index 9638e0c559a956d96218552fdd720bfe7333e546..2e0b9a43e24750fce0e083c37120a47f34d8da8a 100644 (file)
@@ -114,25 +114,12 @@ sub add_val ($$$) {
        $doc->add_value($col, $num);
 }
 
-sub add_values ($$) {
-       my ($doc, $values) = @_;
-
-       my $ts = $values->[PublicInbox::Search::TS];
+sub add_values {
+       my ($doc, $ts, $ds, $num) = @_;
        add_val($doc, PublicInbox::Search::TS, $ts);
-
-       my $num = $values->[PublicInbox::Search::NUM];
-       defined($num) and add_val($doc, PublicInbox::Search::NUM, $num);
-
-       my $bytes = $values->[PublicInbox::Search::BYTES];
-       defined($bytes) and add_val($doc, PublicInbox::Search::BYTES, $bytes);
-
-       my $lines = $values->[PublicInbox::Search::LINES];
-       add_val($doc, PublicInbox::Search::LINES, $lines);
-
-       my $ds = $values->[PublicInbox::Search::DS];
-       add_val($doc, PublicInbox::Search::DS, $ds);
        my $yyyymmdd = strftime('%Y%m%d', gmtime($ds));
        add_val($doc, PublicInbox::Search::YYYYMMDD, $yyyymmdd);
+       defined($num) and add_val($doc, PublicInbox::Search::NUM, $num);
 }
 
 sub index_users ($$) {
@@ -295,8 +282,10 @@ sub add_message {
                }
 
                my $lines = $mime->body_raw =~ tr!\n!\n!;
-               my @values = ($smsg->ds, $num, $bytes, $lines, $smsg->ts);
-               add_values($doc, \@values);
+               $smsg->{lines} = $mime->body_raw =~ tr!\n!\n!;
+               defined $bytes or $bytes = length($mime->as_string);
+               $smsg->{bytes} = $bytes;
+               add_values($doc, $smsg->ts, $smsg->ds, $num);
 
                my $tg = $self->term_generator;
 
@@ -366,8 +355,8 @@ sub add_message {
 
                $self->delete_article($num) if defined $num; # for reindexing
                if ($skel) {
-                       push @values, $mids, $xpath, $data;
-                       $skel->index_skeleton(\@values);
+                       my @vals = ($smsg->ts, $num, $mids, $xpath, $data);
+                       $skel->index_skeleton(\@vals);
                        $doc->add_boolean_term('Q' . $_) foreach @$mids;
                        $doc->add_boolean_term('XNUM' . $num) if defined $num;
                        $doc_id = $self->{xdb}->add_document($doc);
@@ -539,9 +528,9 @@ sub link_and_save {
        $doc->add_boolean_term('XPATH' . $xpath) if defined $xpath;
        $doc->add_boolean_term('Q' . $_) foreach @$mids;
 
-       my $vivified = 0;
        $self->{skel} and die "Should not have read-only skel here\n";;
        foreach my $mid (@$mids) {
+               my $vivified = 0;
                $self->each_smsg_by_mid($mid, sub {
                        my ($cur) = @_;
                        my $type = $cur->type;
@@ -563,10 +552,8 @@ sub link_and_save {
                        ++$vivified;
                        1;
                });
-       }
-       if ($vivified > 1) {
-               my $id = '<'.join('> <', @$mids).'>';
-               warn "BUG: vivified multiple ($vivified) ghosts for $id\n";
+               $vivified > 1 and warn
+                       "BUG: vivified multiple ($vivified) ghosts for $mid\n";
        }
        # not really important, but we return any vivified ghost docid, here:
        return $doc_id if defined $doc_id;