1 # Copyright (C) all contributors <meta@public-inbox.org>
2 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
4 # used by PublicInbox::SearchView and PublicInbox::WwwListing
5 package PublicInbox::SearchQuery;
8 use URI::Escape qw(uri_escape);
9 use PublicInbox::MID qw(MID_ESC);
13 my ($class, $qp) = @_;
15 my $r = $qp->{r}; # relevance
16 my $t = $qp->{t}; # collapse threads
17 my ($l) = (($qp->{l} || '') =~ /([0-9]+)/);
18 $l = $LIM if !$l || $l > $LIM;
19 my ($o) = (($qp->{o} || '0') =~ /(-?[0-9]+)/);
25 r => (defined $r && $r ne '0'),
26 t => (defined $t && $t ne '0'),
31 my ($self, %override) = @_;
33 if (scalar(keys(%override))) {
34 $self = bless { (%$self, %override) }, ref($self);
37 if (defined(my $q = $self->{'q'})) {
38 $q = uri_escape($q, MID_ESC);
39 $q =~ s/%20/+/g; # improve URL readability
42 if (my $o = $self->{o}) { # ignore o == 0
45 if (my $l = $self->{l}) {
46 $qs .= "&l=$l" unless $l == $LIM;
48 for my $bool (qw(r t)) {
49 $qs .= "&$bool" if $self->{$bool};
51 if (my $x = $self->{x}) {
52 $qs .= "&x=$x" if ($x eq 't' || $x eq 'A' || $x eq 'm');