| 1 | package App::ElasticSearch::Utilities::QueryString::Nested; | ||||||||||
| 2 | # ABSTRACT: Implement the proposed Elasticsearch nested query 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 App::ElasticSearch::Utilities::QueryString; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 10 | 2 | ▶ | use CLI::Helpers qw(:output); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 11 | 2 | ▶ | use namespace::autoclean; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 12 | |||||||||||
| 13 | 2 | ▶ | use Moo; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 14 | 1 | with 'App::ElasticSearch::Utilities::QueryString::Plugin'; | |||||||||
| 15 | |||||||||||
| 16 | |||||||||||
| 17 | has 'qs' => ( | ||||||||||
| 18 | is => 'ro', | ||||||||||
| 19 | init_arg => undef, | ||||||||||
| 20 | 1 | ▶ | default => sub { App::ElasticSearch::Utilities::QueryString->new() }, | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 21 | 1 | handles => [qw(expand_query_string)], | |||||||||
| 22 | ); | ||||||||||
| 23 | |||||||||||
| 24 | 1 | my %Reserved = map { $_ => 1 } qw( _prefix_ _exists_ _missing_ ); | |||||||||
| 25 | |||||||||||
| 26 | |||||||||||
| 27 | 4 | ▶ | sub handle_token { | ||||||||
|
Subroutine
handle_token: called CC=6 SCAR=25.1
Pod
undocumented
| |||||||||||
| 28 | 4 | my ($self,$token) = @_; | |||||||||
| 29 | 4 | debug(sprintf "%s - evaluating token '%s'", $self->name, $token); | |||||||||
| 30 | |||||||||||
| 31 | # split on spaces | ||||||||||
| 32 | 4 | my @subtokens = split /\s+/, $token; | |||||||||
| 33 | |||||||||||
| 34 | # check our first token for double colons | ||||||||||
| 35 | 4 | my ($path,$remainder) = split /:"?/, shift @subtokens, 2; | |||||||||
| 36 | |||||||||||
| 37 | 4 | ▶ | return if exists $Reserved{$path}; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 38 | 4 | ▶ | return unless $remainder; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 39 | |||||||||||
| 40 | # If we're nested theres a second colon in there somewhere | ||||||||||
| 41 | 4 | ▶ | if( $remainder =~ /^[\w\.]+:.+/ ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 42 | 0 | ▶ | if( $remainder =~ /^[0-9a-fA-F]{2}(?::[0-9a-fA-F]{2}){2,5}/ ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 43 | # This is a mac address, skip it | ||||||||||
| 44 | 0 | return; | |||||||||
| 45 | } | ||||||||||
| 46 | 0 | ▶ | $subtokens[-1] =~ s/"$// if @subtokens; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 47 | 0 | debug(sprintf "%s - Found nested query, path is %s, remainder: %s", $self->name, $path,$remainder); | |||||||||
| 48 | 0 | my $q = $self->expand_query_string($remainder,@subtokens); | |||||||||
| 49 | 0 | debug_var($q->query); | |||||||||
| 50 | 0 | return [{ nested => {query => $q->query, path => $path}}]; | |||||||||
| 51 | } | ||||||||||
| 52 | 4 | return; | |||||||||
| 53 | } | ||||||||||
| 54 | |||||||||||
| 55 | # Return True; | ||||||||||
| 56 | 1 | 1; | |||||||||
| 57 | |||||||||||
| 58 | __END__ | ||||||||||