1 # Copyright (C) 2015-2021 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;
22 o => (($qp->{o} || '0') =~ /(-?[0-9]+)/),
24 r => (defined $r && $r ne '0'),
25 t => (defined $t && $t ne '0'),
30 my ($self, %override) = @_;
32 if (scalar(keys(%override))) {
33 $self = bless { (%$self, %override) }, ref($self);
36 if (defined(my $q = $self->{'q'})) {
37 $q = uri_escape($q, MID_ESC);
38 $q =~ s/%20/+/g; # improve URL readability
41 if (my $o = $self->{o}) { # ignore o == 0
44 if (my $l = $self->{l}) {
45 $qs .= "&l=$l" unless $l == $LIM;
47 for my $bool (qw(r t)) {
48 $qs .= "&$bool" if $self->{$bool};
50 if (my $x = $self->{x}) {
51 $qs .= "&x=$x" if ($x eq 't' || $x eq 'A' || $x eq 'm');