| 1 | package App::ElasticSearch::Utilities::QueryString::Ranges; | ||||||||||
| 2 | # ABSTRACT: Implement parsing comparison operators to Equivalent Lucene syntax | ||||||||||
| 3 | |||||||||||
| 4 | 2 | ▶ | use v5.16; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | 2 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | |||||||||||
| 7 | 1 | our $VERSION = '9.1'; # VERSION | |||||||||
| 8 | |||||||||||
| 9 | 2 | ▶ | use CLI::Helpers qw(:output); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 10 | 2 | ▶ | use namespace::autoclean; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 11 | |||||||||||
| 12 | 2 | ▶ | use Moo; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 13 | 1 | with 'App::ElasticSearch::Utilities::QueryString::Plugin'; | |||||||||
| 14 | |||||||||||
| 15 | 1 | ▶ | sub _build_priority { 20; } | ||||||||
|
Subroutine
_build_priority: called CC=1 SCAR=0.0
| |||||||||||
| 16 | |||||||||||
| 17 | 1 | my %Operators = ( | |||||||||
| 18 | '<' => { side => 'left', op => 'lt' }, | ||||||||||
| 19 | '<=' => { side => 'left', op => 'lte' }, | ||||||||||
| 20 | '>' => { side => 'right', op => 'gt' }, | ||||||||||
| 21 | '>=' => { side => 'right', op => 'gte' }, | ||||||||||
| 22 | ); | ||||||||||
| 23 | 1 | my $op_match = join('|', map { quotemeta } sort { length $b <=> length $a } keys %Operators); | |||||||||
| 24 | |||||||||||
| 25 | |||||||||||
| 26 | 7 | ▶ | sub handle_token { | ||||||||
|
Subroutine
handle_token: called CC=6 SCAR=22.4
Pod
undocumented
| |||||||||||
| 27 | 7 | my ($self,$token) = @_; | |||||||||
| 28 | |||||||||||
| 29 | 7 | debug(sprintf "%s - evaluating token '%s'", $self->name, $token); | |||||||||
| 30 | 7 | my ($k,$v) = split /:/, $token, 2; | |||||||||
| 31 | |||||||||||
| 32 | 7 | ▶ | return unless $v; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 33 | |||||||||||
| 34 | 7 | my %sides = (); | |||||||||
| 35 | 7 | my %range = (); | |||||||||
| 36 | 7 | foreach my $range (split /\,/, $v) { | |||||||||
| 37 | 7 | ▶ | if( my($symbol,$value) = ( $range =~ /^($op_match)(.+)$/ ) ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 38 | 0 | 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 | 0 | ▶ | if $sides{$side}; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 42 | 0 | $sides{$side} = 1; | |||||||||
| 43 | 0 | $range{$Operators{$symbol}->{op}} = $value; | |||||||||
| 44 | } | ||||||||||
| 45 | } | ||||||||||
| 46 | |||||||||||
| 47 | 7 | ▶ | return unless scalar keys %range; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 48 | |||||||||||
| 49 | 0 | return { condition => { range => { $k => \%range } } }; | |||||||||
| 50 | } | ||||||||||
| 51 | |||||||||||
| 52 | # Return True; | ||||||||||
| 53 | 1 | 1; | |||||||||
| 54 | |||||||||||
| 55 | __END__ | ||||||||||