1 # Copyright (C) 2015-2020 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
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 my $q = uri_escape($self->{'q'}, MID_ESC);
37 $q =~ s/%20/+/g; # improve URL readability
40 if (my $o = $self->{o}) { # ignore o == 0
43 if (my $l = $self->{l}) {
44 $qs .= "&l=$l" unless $l == $LIM;
46 for my $bool (qw(r t)) {
47 $qs .= "&$bool" if $self->{$bool};
49 if (my $x = $self->{x}) {
50 $qs .= "&x=$x" if ($x eq 't' || $x eq 'A' || $x eq 'm');