]> Sergey Matveev's repositories - public-inbox.git/blobdiff - lib/PublicInbox/SearchView.pm
wwwstream: improve documentation and variable naming
[public-inbox.git] / lib / PublicInbox / SearchView.pm
index 80a2ff7c28e68ab9fe178919f481d24fcde8e708..fbba9c4984f03f0a3d08a04d53c8fea730050b27 100644 (file)
@@ -8,10 +8,10 @@ use warnings;
 use PublicInbox::SearchMsg;
 use PublicInbox::Hval qw/ascii_html/;
 use PublicInbox::View;
-use PublicInbox::MID qw(mid2path mid_mime mid_clean);
+use PublicInbox::MID qw(mid2path mid_mime mid_clean mid_escape);
 use Email::MIME;
 require PublicInbox::Git;
-require PublicInbox::Thread;
+require PublicInbox::SearchThread;
 our $LIM = 50;
 
 sub noop {}
@@ -74,7 +74,7 @@ sub mset_summary {
                my $s = ascii_html($smsg->subject);
                my $f = ascii_html($smsg->from_name);
                my $ts = PublicInbox::View::fmt_ts($smsg->ts);
-               my $mid = PublicInbox::Hval->new_msgid($smsg->mid)->as_href;
+               my $mid = PublicInbox::Hval->new_msgid($smsg->mid)->{href};
                $$res .= qq{$rank. <b><a\nhref="$mid/">}.
                        $s . "</a></b>\n";
                $$res .= "$pfx  - by $f @ $ts UTC [$pct%]\n\n";
@@ -85,12 +85,11 @@ sub mset_summary {
 
 sub err_txt {
        my ($ctx, $err) = @_;
-       my $u = '//xapian.org/docs/queryparser.html';
-       $u = PublicInbox::Hval::prurl($ctx->{env}, $u);
+       my $u = $ctx->{-inbox}->base_url($ctx->{env}) . '_/text/help/';
        $err =~ s/^\s*Exception:\s*//; # bad word to show users :P
        $err = ascii_html($err);
        "\nBad query: <b>$err</b>\n" .
-               qq{See <a\nhref="$u">$u</a> for Xapian query syntax};
+               qq{See <a\nhref="$u">$u</a> for help on using search};
 }
 
 sub search_nav_top {
@@ -149,18 +148,17 @@ sub mset_thread {
                my $i = $_;
                my $m = PublicInbox::SearchMsg->load_doc($i->get_document);
                $pct{$m->mid} = $i->get_percent;
-               $m = $m->mini_mime;
                $m;
        } ($mset->items);
 
-       my $th = PublicInbox::Thread->new(@m);
+       my $th = PublicInbox::SearchThread->new(\@m);
        $th->thread;
        if ($q->{r}) { # order by relevance
                $th->order(sub {
-                       sort { (eval { $pct{$b->topmost->messageid} } || 0)
+                       [ sort { (eval { $pct{$b->topmost->{id}} } || 0)
                                        <=>
-                               (eval { $pct{$a->topmost->messageid} } || 0)
-                       } @_;
+                               (eval { $pct{$a->topmost->{id}} } || 0)
+                       } @{$_[0]} ];
                });
        } else { # order by time (default for threaded view)
                $th->order(*PublicInbox::View::sort_ts);
@@ -186,8 +184,7 @@ sub mset_thread {
        sub {
                return unless $msgs;
                while ($mime = shift @$msgs) {
-                       my $mid = mid_clean(mid_mime($mime));
-                       $mime = $inbox->msg_by_mid($mid) and last;
+                       $mime = $inbox->msg_by_smsg($mime) and last;
                }
                if ($mime) {
                        $mime = Email::MIME->new($mime);
@@ -223,7 +220,7 @@ sub adump {
        $x = qq{$x - search results};
        $feed_opts->{atomurl} = $feed_opts->{url} . '?'. $q->qs_html;
        $feed_opts->{url} .= '?'. $q->qs_html(x => undef);
-       $x = PublicInbox::Feed::atom_header($feed_opts, $x);
+       $x = PublicInbox::Feed::atom_header($feed_opts, "<title>$x</title>");
        $fh->write($x. PublicInbox::Feed::feed_updated());
 
        for ($mset->items) {
@@ -239,6 +236,7 @@ package PublicInbox::SearchQuery;
 use strict;
 use warnings;
 use PublicInbox::Hval;
+use PublicInbox::MID qw(mid_escape);
 
 sub new {
        my ($class, $qp) = @_;
@@ -263,7 +261,7 @@ sub qs_html {
                $self = $tmp;
        }
 
-       my $q = PublicInbox::Hval->new($self->{'q'})->as_href;
+       my $q = mid_escape($self->{'q'});
        $q =~ s/%20/+/g; # improve URL readability
        my $qs = "q=$q";