about summary refs log tree commit homepage
path: root/lib/PublicInbox/Search.pm
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2015-08-15 09:28:33 +0000
committerEric Wong <e@80x24.org>2015-08-15 19:15:40 +0000
commit7edf30e5349ab5566815e5050e9ba0f53e1d0bb9 (patch)
treeaa46cb0560f187e197614a4530efbe23969f27d1 /lib/PublicInbox/Search.pm
parentd7fcdec712accc212bcfa35e50ade1233eb9beb3 (diff)
downloadpublic-inbox-7edf30e5349ab5566815e5050e9ba0f53e1d0bb9.tar.gz
This will relieve callers of the need to decode the data
we store internally in Xapian
Diffstat (limited to 'lib/PublicInbox/Search.pm')
-rw-r--r--lib/PublicInbox/Search.pm34
1 files changed, 10 insertions, 24 deletions
diff --git a/lib/PublicInbox/Search.pm b/lib/PublicInbox/Search.pm
index e88bfb16..c9c12c0b 100644
--- a/lib/PublicInbox/Search.pm
+++ b/lib/PublicInbox/Search.pm
@@ -8,8 +8,6 @@ use PublicInbox::SearchMsg;
 use base qw/Exporter/;
 use Search::Xapian qw/:standard/;
 require PublicInbox::View;
-use Date::Parse qw/str2time/;
-use POSIX qw//;
 use Email::MIME;
 use PublicInbox::MID qw/mid_clean mid_compressed/;
 
@@ -109,8 +107,7 @@ sub add_message {
                         $doc->add_term(xpfx('mid') . $mid);
                 }
 
-                my $subj = $mime->header('Subject');
-                $subj = '' unless defined $subj;
+                my $subj = $smsg->subject;
 
                 if (length $subj) {
                         $doc->add_term(xpfx('subject') . $subj);
@@ -119,23 +116,12 @@ sub add_message {
                         $doc->add_term(xpfx('path') . $path);
                 }
 
-                my $from = $mime->header('From') || '';
-                my @from;
-
-                if ($from) {
-                        @from = Email::Address->parse($from);
-                        $from = $from[0]->name;
-                }
-
-                my $ts = eval { str2time($mime->header('Date')) } || 0;
-                my $date = POSIX::strftime('%Y-%m-%d %H:%M', gmtime($ts));
-                $ts = Search::Xapian::sortable_serialise($ts);
+                my $from = $smsg->from_name;
+                my $date = $smsg->date;
+                my $ts = Search::Xapian::sortable_serialise($smsg->ts);
                 $doc->add_value(PublicInbox::Search::TS, $ts);
 
-                # this is what we show in index results:
-                $subj =~ tr/\n/ /;
-                $from =~ tr/\n/ /;
-                $doc->set_data("$mid\n$subj\n$from\n$date");
+                $doc->set_data($smsg->to_doc_data);
 
                 my $tg = $self->term_generator;
 
@@ -145,10 +131,8 @@ sub add_message {
                 $tg->index_text($subj) if $subj;
                 $tg->increase_termpos;
 
-                if (@from) {
-                        $tg->index_text($from[0]->format);
-                        $tg->increase_termpos;
-                }
+                $tg->index_text($smsg->from->format);
+                $tg->increase_termpos;
 
                 $mime->walk_parts(sub {
                         my ($part) = @_;
@@ -265,7 +249,9 @@ sub do_enquire {
         my $offset = $opts->{offset} || 0;
         my $limit = $opts->{limit} || 50;
         my $mset = $enquire->get_mset($offset, $limit);
-        my @msgs = map { $_->get_document->get_data } $mset->items;
+        my @msgs = map {
+                PublicInbox::SearchMsg->load_doc($_->get_document);
+        } $mset->items;
 
         { count => $mset->get_matches_estimated, msgs => \@msgs }
 }