]> Sergey Matveev's repositories - public-inbox.git/blobdiff - lib/PublicInbox/SearchQuery.pm
No ext_urls
[public-inbox.git] / lib / PublicInbox / SearchQuery.pm
index ce1eae121a9d0498825346faace2916ad06dfe97..96246c5385d8c0ca8fcc18191be2b4e1b34d71a2 100644 (file)
@@ -1,7 +1,7 @@
-# Copyright (C) 2015-2020 all contributors <meta@public-inbox.org>
+# Copyright (C) all contributors <meta@public-inbox.org>
 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
 
-# used by PublicInbox::SearchView
+# used by PublicInbox::SearchView and PublicInbox::WwwListing
 package PublicInbox::SearchQuery;
 use strict;
 use v5.10.1;
@@ -12,15 +12,18 @@ our $LIM = 200;
 sub new {
        my ($class, $qp) = @_;
 
-       my $r = $qp->{r};
+       my $r = $qp->{r}; # relevance
+       my $t = $qp->{t}; # collapse threads
        my ($l) = (($qp->{l} || '') =~ /([0-9]+)/);
        $l = $LIM if !$l || $l > $LIM;
+       my ($o) = (($qp->{o} || '0') =~ /(-?[0-9]+)/);
        bless {
                q => $qp->{'q'},
                x => $qp->{x} || '',
-               o => (($qp->{o} || '0') =~ /(-?[0-9]+)/),
+               o => $o,
                l => $l,
                r => (defined $r && $r ne '0'),
+               t => (defined $t && $t ne '0'),
        }, $class;
 }
 
@@ -30,19 +33,20 @@ sub qs_html {
        if (scalar(keys(%override))) {
                $self = bless { (%$self, %override) }, ref($self);
        }
-
-       my $q = uri_escape($self->{'q'}, MID_ESC);
-       $q =~ s/%20/+/g; # improve URL readability
-       my $qs = "q=$q";
-
+       my $qs = '';
+       if (defined(my $q = $self->{'q'})) {
+               $q = uri_escape($q, MID_ESC);
+               $q =~ s/%20/+/g; # improve URL readability
+               $qs .= "q=$q";
+       }
        if (my $o = $self->{o}) { # ignore o == 0
                $qs .= "&amp;o=$o";
        }
        if (my $l = $self->{l}) {
                $qs .= "&amp;l=$l" unless $l == $LIM;
        }
-       if (my $r = $self->{r}) {
-               $qs .= "&amp;r";
+       for my $bool (qw(r t)) {
+               $qs .= "&amp;$bool" if $self->{$bool};
        }
        if (my $x = $self->{x}) {
                $qs .= "&amp;x=$x" if ($x eq 't' || $x eq 'A' || $x eq 'm');