From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on dcvr.yhbt.net X-Spam-Level: X-Spam-Status: No, score=-4.0 required=3.0 tests=ALL_TRUSTED,AWL,BAYES_00 shortcircuit=no autolearn=ham autolearn_force=no version=3.4.2 Received: from localhost (dcvr.yhbt.net [127.0.0.1]) by dcvr.yhbt.net (Postfix) with ESMTP id 390961FB06 for ; Thu, 20 Aug 2020 20:25:00 +0000 (UTC) From: Eric Wong To: meta@public-inbox.org Subject: [PATCH 12/23] searchquery: split off from searchview Date: Thu, 20 Aug 2020 20:24:46 +0000 Message-Id: <20200820202457.21042-13-e@yhbt.net> In-Reply-To: <20200820202457.21042-1-e@yhbt.net> References: <20200820202457.21042-1-e@yhbt.net> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: Since this was already a separate package, split it off into its own file since SearchView may not handle inbox groups. --- MANIFEST | 1 + lib/PublicInbox/SearchQuery.pm | 53 ++++++++++++++++++++++++++++++++++ lib/PublicInbox/SearchView.pm | 53 ++-------------------------------- 3 files changed, 57 insertions(+), 50 deletions(-) create mode 100644 lib/PublicInbox/SearchQuery.pm diff --git a/MANIFEST b/MANIFEST index 6cb5f6bf..d86d3b15 100644 --- a/MANIFEST +++ b/MANIFEST @@ -173,6 +173,7 @@ lib/PublicInbox/SaPlugin/ListMirror.pod lib/PublicInbox/Search.pm lib/PublicInbox/SearchIdx.pm lib/PublicInbox/SearchIdxShard.pm +lib/PublicInbox/SearchQuery.pm lib/PublicInbox/SearchThread.pm lib/PublicInbox/SearchView.pm lib/PublicInbox/Sigfd.pm diff --git a/lib/PublicInbox/SearchQuery.pm b/lib/PublicInbox/SearchQuery.pm new file mode 100644 index 00000000..ce1eae12 --- /dev/null +++ b/lib/PublicInbox/SearchQuery.pm @@ -0,0 +1,53 @@ +# Copyright (C) 2015-2020 all contributors +# License: AGPL-3.0+ + +# used by PublicInbox::SearchView +package PublicInbox::SearchQuery; +use strict; +use v5.10.1; +use URI::Escape qw(uri_escape); +use PublicInbox::MID qw(MID_ESC); +our $LIM = 200; + +sub new { + my ($class, $qp) = @_; + + my $r = $qp->{r}; + my ($l) = (($qp->{l} || '') =~ /([0-9]+)/); + $l = $LIM if !$l || $l > $LIM; + bless { + q => $qp->{'q'}, + x => $qp->{x} || '', + o => (($qp->{o} || '0') =~ /(-?[0-9]+)/), + l => $l, + r => (defined $r && $r ne '0'), + }, $class; +} + +sub qs_html { + my ($self, %override) = @_; + + 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"; + + if (my $o = $self->{o}) { # ignore o == 0 + $qs .= "&o=$o"; + } + if (my $l = $self->{l}) { + $qs .= "&l=$l" unless $l == $LIM; + } + if (my $r = $self->{r}) { + $qs .= "&r"; + } + if (my $x = $self->{x}) { + $qs .= "&x=$x" if ($x eq 't' || $x eq 'A' || $x eq 'm'); + } + $qs; +} + +1; diff --git a/lib/PublicInbox/SearchView.pm b/lib/PublicInbox/SearchView.pm index 5d77469e..28d9ce5d 100644 --- a/lib/PublicInbox/SearchView.pm +++ b/lib/PublicInbox/SearchView.pm @@ -4,15 +4,15 @@ # Displays search results for the web interface package PublicInbox::SearchView; use strict; -use warnings; -use URI::Escape qw(uri_unescape uri_escape); +use v5.10.1; +use URI::Escape qw(uri_unescape); use PublicInbox::Smsg; use PublicInbox::Hval qw(ascii_html obfuscate_addrs mid_href); use PublicInbox::View; use PublicInbox::WwwAtomStream; use PublicInbox::WwwStream qw(html_oneshot); use PublicInbox::SearchThread; -our $LIM = 200; +use PublicInbox::SearchQuery; my %rmap_inc; sub mbox_results { @@ -336,51 +336,4 @@ sub adump_i { } } -package PublicInbox::SearchQuery; -use strict; -use warnings; -use URI::Escape qw(uri_escape); -use PublicInbox::MID qw(MID_ESC); - -sub new { - my ($class, $qp) = @_; - - my $r = $qp->{r}; - my ($l) = (($qp->{l} || '') =~ /([0-9]+)/); - $l = $LIM if !$l || $l > $LIM; - bless { - q => $qp->{'q'}, - x => $qp->{x} || '', - o => (($qp->{o} || '0') =~ /(-?[0-9]+)/), - l => $l, - r => (defined $r && $r ne '0'), - }, $class; -} - -sub qs_html { - my ($self, %override) = @_; - - 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"; - - if (my $o = $self->{o}) { # ignore o == 0 - $qs .= "&o=$o"; - } - if (my $l = $self->{l}) { - $qs .= "&l=$l" unless $l == $LIM; - } - if (my $r = $self->{r}) { - $qs .= "&r"; - } - if (my $x = $self->{x}) { - $qs .= "&x=$x" if ($x eq 't' || $x eq 'A' || $x eq 'm'); - } - $qs; -} - 1;