]> Sergey Matveev's repositories - public-inbox.git/commitdiff
searchquery: split off from searchview
authorEric Wong <e@yhbt.net>
Thu, 20 Aug 2020 20:24:46 +0000 (20:24 +0000)
committerEric Wong <e@yhbt.net>
Thu, 20 Aug 2020 21:11:15 +0000 (21:11 +0000)
Since this was already a separate package, split it off
into its own file since SearchView may not handle inbox
groups.

MANIFEST
lib/PublicInbox/SearchQuery.pm [new file with mode: 0644]
lib/PublicInbox/SearchView.pm

index 6cb5f6bf42df271e98ce5f248b12f174596fafab..d86d3b1576e6d383709d1f6ed8ce9af9dd931165 100644 (file)
--- 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 (file)
index 0000000..ce1eae1
--- /dev/null
@@ -0,0 +1,53 @@
+# Copyright (C) 2015-2020 all contributors <meta@public-inbox.org>
+# License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
+
+# 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 .= "&amp;o=$o";
+       }
+       if (my $l = $self->{l}) {
+               $qs .= "&amp;l=$l" unless $l == $LIM;
+       }
+       if (my $r = $self->{r}) {
+               $qs .= "&amp;r";
+       }
+       if (my $x = $self->{x}) {
+               $qs .= "&amp;x=$x" if ($x eq 't' || $x eq 'A' || $x eq 'm');
+       }
+       $qs;
+}
+
+1;
index 5d77469ed522bcbf14f09904275860bd876f651b..28d9ce5dd940ba337079ba39f2ae61fadec056b4 100644 (file)
@@ -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 .= "&amp;o=$o";
-       }
-       if (my $l = $self->{l}) {
-               $qs .= "&amp;l=$l" unless $l == $LIM;
-       }
-       if (my $r = $self->{r}) {
-               $qs .= "&amp;r";
-       }
-       if (my $x = $self->{x}) {
-               $qs .= "&amp;x=$x" if ($x eq 't' || $x eq 'A' || $x eq 'm');
-       }
-       $qs;
-}
-
 1;