]> Sergey Matveev's repositories - public-inbox.git/blobdiff - lib/PublicInbox/SearchIdx.pm
search: increase term positions for each quoted hunk
[public-inbox.git] / lib / PublicInbox / SearchIdx.pm
index cd27a29459e2360d1607cc7267d910af3aa8acb4..0e499ad16af0a6155dacc0520d54d9cee6489786 100644 (file)
@@ -129,15 +129,16 @@ sub index_users ($$) {
 
        $tg->index_text($from, 1, 'A'); # A - author
        $tg->increase_termpos;
-
        $tg->index_text($to, 1, 'XTO') if $to ne '';
+       $tg->increase_termpos;
        $tg->index_text($cc, 1, 'XCC') if $cc ne '';
-       my $tc = join("\t", $to, $cc);
-       $tg->index_text($tc, 1, 'XTC') if $tc ne '';
-       my $tcf = join("\t", $tc, $from);
-       $tg->index_text($tcf, 1, 'XTCF') if $tcf ne '';
+       $tg->increase_termpos;
+}
 
-       $tg->index_text($from);
+sub index_body ($$$) {
+       my ($tg, $lines, $inc) = @_;
+       $tg->index_text(join("\n", @$lines), $inc, $inc ? 'XNQ' : 'XQUOT');
+       @$lines = ();
        $tg->increase_termpos;
 }
 
@@ -173,12 +174,7 @@ sub add_message {
                my $tg = $self->term_generator;
 
                $tg->set_document($doc);
-               if ($subj) {
-                       $tg->index_text($subj, 1, 'S');
-                       $tg->index_text($subj, 1, 'XBS');
-               }
-               $tg->increase_termpos;
-               $tg->index_text($subj) if $subj;
+               $tg->index_text($subj, 1, 'S') if $subj;
                $tg->increase_termpos;
 
                index_users($tg, $smsg);
@@ -195,34 +191,20 @@ sub add_message {
                        $part->body_set('');
                        my @lines = split(/\n/, $body);
                        while (defined(my $l = shift @lines)) {
-                               if ($l =~ /^\s*>/) {
+                               if ($l =~ /^>/) {
+                                       index_body($tg, \@orig, 1) if @orig;
                                        push @quot, $l;
                                } else {
+                                       index_body($tg, \@quot, 0) if @quot;
                                        push @orig, $l;
                                }
                        }
-                       if (@quot) {
-                               my $s = join("\n", @quot);
-                               @quot = ();
-                               $tg->index_text($s, 1, 'XQUOT');
-                               $tg->index_text($s, 0, 'XBS');
-                               $tg->index_text($s, 0, 'XBODY');
-                               $tg->index_text($s, 0);
-                               $tg->increase_termpos;
-                       }
-                       if (@orig) {
-                               my $s = join("\n", @orig);
-                               @orig = ();
-                               $tg->index_text($s, 1, 'XNQ');
-                               $tg->index_text($s, 1, 'XBS');
-                               $tg->index_text($s, 1, 'XBODY');
-                               $tg->index_text($s);
-                               $tg->increase_termpos;
-                       }
+                       index_body($tg, \@quot, 0) if @quot;
+                       index_body($tg, \@orig, 1) if @orig;
                });
 
                link_message($self, $smsg, $old_tid);
-               $tg->index_text($mid, 1);
+               $tg->index_text($mid, 1, 'XMID');
                $doc->set_data($smsg->to_doc_data($blob));
 
                if (my $altid = $self->{-altid}) {