]> Sergey Matveev's repositories - public-inbox.git/blobdiff - lib/PublicInbox/SearchView.pm
thread: remove Mail::Thread dependency
[public-inbox.git] / lib / PublicInbox / SearchView.pm
index 30a310c9f58ceede52857d3b07d23668eaedcf6b..da31109357a0a579fa5c6aa04cb1bf2d1a59c4c1 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 {}
@@ -38,11 +38,11 @@ sub sres_top_html {
        my $cb;
        if ($err) {
                $code = 400;
-               $ctx->{-html_tip} = '<pre>'.err_txt($ctx, $err).'</pre><hr />';
+               $ctx->{-html_tip} = '<pre>'.err_txt($ctx, $err).'</pre><hr>';
                $cb = *noop;
        } elsif ($total == 0) {
                $code = 404;
-               $ctx->{-html_tip} = "<pre>\n[No results found]</pre><hr />";
+               $ctx->{-html_tip} = "<pre>\n[No results found]</pre><hr>";
                $cb = *noop;
        } else {
                my $x = $q->{x};
@@ -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->{cgi}->{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 {
@@ -126,7 +125,7 @@ sub search_nav_bot {
        my $o = $q->{o};
        my $end = $o + $nr;
        my $beg = $o + 1;
-       my $rv = "</pre><hr /><pre>Results $beg-$end of $total";
+       my $rv = "</pre><hr><pre>Results $beg-$end of $total";
        my $n = $o + $LIM;
 
        if ($n < $total) {
@@ -153,7 +152,7 @@ sub mset_thread {
                $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 {
@@ -176,6 +175,7 @@ sub mset_thread {
        $ctx->{prev_attr} = '';
        $ctx->{prev_level} = 0;
        $ctx->{seen} = {};
+       $ctx->{s_nr} = scalar(@m).'+ results';
 
        PublicInbox::View::walk_thread($th, $ctx,
                *PublicInbox::View::pre_thread);
@@ -190,7 +190,8 @@ sub mset_thread {
                }
                if ($mime) {
                        $mime = Email::MIME->new($mime);
-                       return PublicInbox::View::index_entry($mime, $ctx);
+                       return PublicInbox::View::index_entry($mime, $ctx,
+                               scalar @$msgs);
                }
                $msgs = undef;
                $skel .= "\n</pre>";
@@ -237,6 +238,7 @@ package PublicInbox::SearchQuery;
 use strict;
 use warnings;
 use PublicInbox::Hval;
+use PublicInbox::MID qw(mid_escape);
 
 sub new {
        my ($class, $qp) = @_;
@@ -261,7 +263,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";