]> Sergey Matveev's repositories - public-inbox.git/blobdiff - lib/PublicInbox/SearchView.pm
update copyrights for 2018
[public-inbox.git] / lib / PublicInbox / SearchView.pm
index 39400d6d4d16c7c0edfe6e97bf988fc3ab7c1540..53b88c34d284f67194e53272b3a3bf2a1a95db3e 100644 (file)
@@ -1,5 +1,5 @@
-# Copyright (C) 2015 all contributors <meta@public-inbox.org>
-# License: AGPLv3 or later (https://www.gnu.org/licenses/agpl-3.0.txt)
+# Copyright (C) 2015-2018 all contributors <meta@public-inbox.org>
+# License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
 #
 # Displays search results for the web interface
 package PublicInbox::SearchView;
@@ -18,11 +18,21 @@ our $LIM = 200;
 
 sub noop {}
 
+sub mbox_results {
+       my ($ctx) = @_;
+       my $q = PublicInbox::SearchQuery->new($ctx->{qp});
+       my $x = $q->{x};
+       return PublicInbox::Mbox::mbox_all($ctx, $q->{'q'}) if $x eq 'm';
+       sres_top_html($ctx);
+}
+
 sub sres_top_html {
        my ($ctx) = @_;
        my $q = PublicInbox::SearchQuery->new($ctx->{qp});
-       my $code = 200;
+       my $x = $q->{x};
+       my $query = $q->{'q'};
 
+       my $code = 200;
        # double the limit for expanded views:
        my $opts = {
                limit => $LIM,
@@ -33,7 +43,7 @@ sub sres_top_html {
        my ($mset, $total, $err, $cb);
 retry:
        eval {
-               $mset = $ctx->{srch}->query($q->{'q'}, $opts);
+               $mset = $ctx->{srch}->query($query, $opts);
                $total = $mset->get_matches_estimated;
        };
        $err = $@;
@@ -55,10 +65,9 @@ retry:
                $ctx->{-html_tip} = "<pre>\n[No results found]</pre><hr>";
                $cb = *noop;
        } else {
-               my $x = $q->{x};
                return adump($_[0], $mset, $q, $ctx) if $x eq 'A';
 
-               $ctx->{-html_tip} = search_nav_top($mset, $q, $ctx) . "\n\n";
+               $ctx->{-html_tip} = search_nav_top($mset, $q, $ctx);
                if ($x eq 't') {
                        $cb = mset_thread($ctx, $mset, $q);
                } else {
@@ -129,8 +138,8 @@ sub err_txt {
 
 sub search_nav_top {
        my ($mset, $q, $ctx) = @_;
-
-       my $rv = '<pre>';
+       my $m = $q->qs_html(x => 'm', r => undef);
+       my $rv = qq{<form\naction="?$m"\nmethod="post"><pre>};
        my $initial_q = $ctx->{-uxs_retried};
        if (defined $initial_q) {
                my $rewritten = $q->{'q'};
@@ -164,6 +173,8 @@ sub search_nav_top {
        }
        my $A = $q->qs_html(x => 'A', r => undef);
        $rv .= qq{|<a\nhref="?$A">Atom feed</a>]};
+       $rv .= qq{\n\t\t\t\t\t\tdownload: };
+       $rv .= qq{<input\ntype=submit\nvalue="mbox.gz"/></pre></form><pre>};
 }
 
 sub search_nav_bot {
@@ -327,7 +338,7 @@ sub qs_html {
                $qs .= "&amp;r";
        }
        if (my $x = $self->{x}) {
-               $qs .= "&amp;x=$x" if ($x eq 't' || $x eq 'A');
+               $qs .= "&amp;x=$x" if ($x eq 't' || $x eq 'A' || $x eq 'm');
        }
        $qs;
 }