line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package App::ElasticSearch::Utilities::QueryString::Ranges; |
2
|
|
|
|
|
|
|
# ABSTRACT: Implement parsing comparison operators to Equivalent Lucene syntax |
3
|
|
|
|
|
|
|
|
4
|
1
|
|
|
1
|
|
690
|
use v5.16; |
|
1
|
|
|
|
|
5
|
|
5
|
1
|
|
|
1
|
|
6
|
use warnings; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
44
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
our $VERSION = '8.6'; # VERSION |
8
|
|
|
|
|
|
|
|
9
|
1
|
|
|
1
|
|
6
|
use CLI::Helpers qw(:output); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
8
|
|
10
|
1
|
|
|
1
|
|
134
|
use namespace::autoclean; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
7
|
|
11
|
|
|
|
|
|
|
|
12
|
1
|
|
|
1
|
|
80
|
use Moo; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
14
|
|
13
|
|
|
|
|
|
|
with 'App::ElasticSearch::Utilities::QueryString::Plugin'; |
14
|
|
|
|
|
|
|
|
15
|
1
|
|
|
1
|
|
42
|
sub _build_priority { 20; } |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
my %Operators = ( |
18
|
|
|
|
|
|
|
'<' => { side => 'left', op => 'lt' }, |
19
|
|
|
|
|
|
|
'<=' => { side => 'left', op => 'lte' }, |
20
|
|
|
|
|
|
|
'>' => { side => 'right', op => 'gt' }, |
21
|
|
|
|
|
|
|
'>=' => { side => 'right', op => 'gte' }, |
22
|
|
|
|
|
|
|
); |
23
|
|
|
|
|
|
|
my $op_match = join('|', map { quotemeta } sort { length $b <=> length $a } keys %Operators); |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
sub handle_token { |
27
|
|
|
|
|
|
|
my ($self,$token) = @_; |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
debug(sprintf "%s - evaluating token '%s'", $self->name, $token); |
30
|
|
|
|
|
|
|
my ($k,$v) = split /:/, $token, 2; |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
return unless $v; |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
my %sides = (); |
35
|
|
|
|
|
|
|
my %range = (); |
36
|
|
|
|
|
|
|
foreach my $range (split /\,/, $v) { |
37
|
|
|
|
|
|
|
if( my($symbol,$value) = ( $range =~ /^($op_match)(.+)$/ ) ) { |
38
|
|
|
|
|
|
|
my $side = $Operators{$symbol}->{side}; |
39
|
|
|
|
|
|
|
# Invalid query if two left or right operators |
40
|
|
|
|
|
|
|
die "attempted to set more than one $side-side operator in Range: $token" |
41
|
|
|
|
|
|
|
if $sides{$side}; |
42
|
|
|
|
|
|
|
$sides{$side} = 1; |
43
|
|
|
|
|
|
|
$range{$Operators{$symbol}->{op}} = $value; |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
return unless scalar keys %range; |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
return { condition => { range => { $k => \%range } } }; |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
# Return True; |
53
|
|
|
|
|
|
|
1; |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
__END__ |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
=pod |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
=head1 NAME |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
App::ElasticSearch::Utilities::QueryString::Ranges - Implement parsing comparison operators to Equivalent Lucene syntax |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
=head1 VERSION |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
version 8.6 |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
=head1 SYNOPSIS |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
=head2 App::ElasticSearch::Utilities::QueryString::Ranges |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
This plugin translates some special comparison operators so you don't need to |
72
|
|
|
|
|
|
|
remember them anymore. |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
Example: |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
price:<100 |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
Will translate into a: |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
{ range: { price: { lt: 100 } } } |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
And: |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
price:>50,<100 |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
Will translate to: |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
{ range: { price: { gt: 50, lt: 100 } } } |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
=head3 Supported Operators |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
=over 2 |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
B<gt> via E<gt>, B<gte> via E<gt>=, B<lt> via E<lt>, B<lte> via E<lt>= |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
=back |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
=for Pod::Coverage handle_token |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
=head1 AUTHOR |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
Brad Lhotsky <brad@divisionbyzero.net> |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
This software is Copyright (c) 2023 by Brad Lhotsky. |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
This is free software, licensed under: |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
The (three-clause) BSD License |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
=cut |