]> 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 ae890605d14e56a7386f100ee477786d45c5dc2f..0e499ad16af0a6155dacc0520d54d9cee6489786 100644 (file)
@@ -135,6 +135,13 @@ sub index_users ($$) {
        $tg->increase_termpos;
 }
 
+sub index_body ($$$) {
+       my ($tg, $lines, $inc) = @_;
+       $tg->index_text(join("\n", @$lines), $inc, $inc ? 'XNQ' : 'XQUOT');
+       @$lines = ();
+       $tg->increase_termpos;
+}
+
 sub add_message {
        my ($self, $mime, $bytes, $num, $blob) = @_; # mime = Email::MIME object
        my $db = $self->{xdb};
@@ -184,24 +191,16 @@ 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, 0, 'XQUOT');
-                               $tg->increase_termpos;
-                       }
-                       if (@orig) {
-                               my $s = join("\n", @orig);
-                               @orig = ();
-                               $tg->index_text($s, 1, 'XNQ');
-                               $tg->increase_termpos;
-                       }
+                       index_body($tg, \@quot, 0) if @quot;
+                       index_body($tg, \@orig, 1) if @orig;
                });
 
                link_message($self, $smsg, $old_tid);