about summary refs log tree commit homepage
path: root/lib/PublicInbox/SearchIdx.pm
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2016-09-09 00:01:27 +0000
committerEric Wong <e@80x24.org>2016-09-09 00:02:20 +0000
commit1b14910344c10f85ce29281a5a7803ab3b2971be (patch)
tree119d2be043e751cdd5b22d910002e0731c0f5110 /lib/PublicInbox/SearchIdx.pm
parent6ca633a1360a0974a8ebb117554a856022d797c6 (diff)
downloadpublic-inbox-1b14910344c10f85ce29281a5a7803ab3b2971be.tar.gz
We pay a storage cost for storing positional information
in Xapian, make good use of it by attempting to preserve
it for (hopefully) better search results.
Diffstat (limited to 'lib/PublicInbox/SearchIdx.pm')
-rw-r--r--lib/PublicInbox/SearchIdx.pm23
1 files changed, 11 insertions, 12 deletions
diff --git a/lib/PublicInbox/SearchIdx.pm b/lib/PublicInbox/SearchIdx.pm
index 25452dae..0e499ad1 100644
--- a/lib/PublicInbox/SearchIdx.pm
+++ b/lib/PublicInbox/SearchIdx.pm
@@ -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};
@@ -185,23 +192,15 @@ sub add_message {
                         my @lines = split(/\n/, $body);
                         while (defined(my $l = shift @lines)) {
                                 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);