]> Sergey Matveev's repositories - public-inbox.git/blobdiff - lib/PublicInbox/SearchView.pm
searchview: minor cleanup
[public-inbox.git] / lib / PublicInbox / SearchView.pm
index c42cf2d63fa3c9b99c2ce5fc534addffcebe8fd6..d038dfcac761912f9338783be5ea164469dcbdf7 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;
@@ -10,7 +10,7 @@ use PublicInbox::SearchMsg;
 use PublicInbox::Hval qw/ascii_html obfuscate_addrs/;
 use PublicInbox::View;
 use PublicInbox::WwwAtomStream;
-use PublicInbox::MID qw(mid2path mid_mime mid_clean mid_escape MID_ESC);
+use PublicInbox::MID qw(MID_ESC);
 use PublicInbox::MIME;
 require PublicInbox::Git;
 require PublicInbox::SearchThread;
@@ -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 {
@@ -79,7 +88,7 @@ sub load_doc_retry {
        }
 }
 
-# display non-threaded search results similar to what users expect from
+# display non-nested search results similar to what users expect from
 # regular WWW search engines:
 sub mset_summary {
        my ($ctx, $mset, $q) = @_;
@@ -108,11 +117,11 @@ sub mset_summary {
                        obfuscate_addrs($obfs_ibx, $s);
                        obfuscate_addrs($obfs_ibx, $f);
                }
-               my $ts = PublicInbox::View::fmt_ts($smsg->ts);
+               my $date = PublicInbox::View::fmt_ts($smsg->ds);
                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";
+               $$res .= "$pfx  - by $f @ $date UTC [$pct%]\n\n";
        }
        $$res .= search_nav_bot($mset, $q);
        *noop;
@@ -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'};
@@ -157,21 +166,22 @@ sub search_nav_top {
        my $x = $q->{x};
        if ($x eq '') {
                my $t = $q->qs_html(x => 't');
-               $rv .= qq{<b>summary</b>|<a\nhref="?$t">threaded</a>}
+               $rv .= qq{<b>summary</b>|<a\nhref="?$t">nested</a>}
        } elsif ($q->{x} eq 't') {
                my $s = $q->qs_html(x => '');
-               $rv .= qq{<a\nhref="?$s">summary</a>|<b>threaded</b>};
+               $rv .= qq{<a\nhref="?$s">summary</a>|<b>nested</b>};
        }
        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 {
        my ($mset, $q) = @_;
        my $total = $mset->get_matches_estimated;
-       my $nr = scalar $mset->items;
        my $o = $q->{o};
-       my $end = $o + $nr;
+       my $end = $o + $mset->size;
        my $beg = $o + 1;
        my $rv = '</pre><hr><pre id=t>';
        if ($beg <= $end) {
@@ -216,8 +226,8 @@ sub mset_thread {
        } ($mset->items) ]});
        my $r = $q->{r};
        my $rootset = PublicInbox::SearchThread::thread($msgs,
-               $r ? sort_relevance(\%pct) : *PublicInbox::View::sort_ts,
-               $srch);
+               $r ? sort_relevance(\%pct) : *PublicInbox::View::sort_ds,
+               $ctx);
        my $skel = search_nav_bot($mset, $q). "<pre>";
        my $inbox = $ctx->{-inbox};
        $ctx->{-upfx} = '';
@@ -237,15 +247,14 @@ sub mset_thread {
                *PublicInbox::View::pre_thread);
 
        @$msgs = reverse @$msgs if $r;
-       my $mime;
        sub {
                return unless $msgs;
-               while ($mime = pop @$msgs) {
-                       $mime = $inbox->msg_by_smsg($mime) and last;
+               my $smsg;
+               while (my $m = pop @$msgs) {
+                       $smsg = $inbox->smsg_mime($m) and last;
                }
-               if ($mime) {
-                       $mime = PublicInbox::MIME->new($mime);
-                       return PublicInbox::View::index_entry($mime, $ctx,
+               if ($smsg) {
+                       return PublicInbox::View::index_entry($smsg, $ctx,
                                scalar @$msgs);
                }
                $msgs = undef;
@@ -279,8 +288,7 @@ sub adump {
        PublicInbox::WwwAtomStream->response($ctx, 200, sub {
                while (my $x = shift @items) {
                        $x = load_doc_retry($srch, $x);
-                       $x = $ibx->msg_by_smsg($x) and
-                                       return PublicInbox::MIME->new($x);
+                       $x = $ibx->smsg_mime($x) and return $x;
                }
                return undef;
        });
@@ -327,7 +335,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;
 }