line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package App::ElasticSearch::Utilities::QueryString::Nested; |
2
|
|
|
|
|
|
|
# ABSTRACT: Implement the proposed Elasticsearch nested query syntax |
3
|
|
|
|
|
|
|
|
4
|
1
|
|
|
1
|
|
637
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
30
|
|
5
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
41
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
our $VERSION = '8.5'; # VERSION |
8
|
|
|
|
|
|
|
|
9
|
1
|
|
|
1
|
|
6
|
use App::ElasticSearch::Utilities::QueryString; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
40
|
|
10
|
1
|
|
|
1
|
|
7
|
use CLI::Helpers qw(:output); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
6
|
|
11
|
1
|
|
|
1
|
|
153
|
use namespace::autoclean; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
6
|
|
12
|
|
|
|
|
|
|
|
13
|
1
|
|
|
1
|
|
72
|
use Moo; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
5
|
|
14
|
|
|
|
|
|
|
with 'App::ElasticSearch::Utilities::QueryString::Plugin'; |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
has 'qs' => ( |
18
|
|
|
|
|
|
|
is => 'ro', |
19
|
|
|
|
|
|
|
init_arg => undef, |
20
|
|
|
|
|
|
|
default => sub { App::ElasticSearch::Utilities::QueryString->new() }, |
21
|
|
|
|
|
|
|
handles => [qw(expand_query_string)], |
22
|
|
|
|
|
|
|
); |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
my %Reserved = map { $_ => 1 } qw( _prefix_ _exists_ _missing_ ); |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
sub handle_token { |
28
|
|
|
|
|
|
|
my ($self,$token) = @_; |
29
|
|
|
|
|
|
|
debug(sprintf "%s - evaluating token '%s'", $self->name, $token); |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
# split on spaces |
32
|
|
|
|
|
|
|
my @subtokens = split /\s+/, $token; |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
# check our first token for double colons |
35
|
|
|
|
|
|
|
my ($path,$remainder) = split /:"?/, shift @subtokens, 2; |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
return if exists $Reserved{$path}; |
38
|
|
|
|
|
|
|
return unless $remainder; |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
# If we're nested theres a second colon in there somewhere |
41
|
|
|
|
|
|
|
if( $remainder =~ /^[\w\.]+:.+/ ) { |
42
|
|
|
|
|
|
|
if( $remainder =~ /^[0-9a-fA-F]{2}(?::[0-9a-fA-F]{2}){2,5}/ ) { |
43
|
|
|
|
|
|
|
# This is a mac address, skip it |
44
|
|
|
|
|
|
|
return; |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
$subtokens[-1] =~ s/"$// if @subtokens; |
47
|
|
|
|
|
|
|
debug(sprintf "%s - Found nested query, path is %s, remainder: %s", $self->name, $path,$remainder); |
48
|
|
|
|
|
|
|
my $q = $self->expand_query_string($remainder,@subtokens); |
49
|
|
|
|
|
|
|
debug_var($q->query); |
50
|
|
|
|
|
|
|
return [{ nested => {query => $q->query, path => $path}}]; |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
return; |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
# Return True; |
56
|
|
|
|
|
|
|
1; |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
__END__ |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
=pod |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
=head1 NAME |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
App::ElasticSearch::Utilities::QueryString::Nested - Implement the proposed Elasticsearch nested query syntax |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
=head1 VERSION |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
version 8.5 |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
=head1 SYNOPSIS |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
=head2 App::ElasticSearch::Utilities::QueryString::Nested |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
Implement the proposed nested query syntax early. Example: |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
nested_path:"field:match AND string" |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
=head1 ATTRIBUTES |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
=head2 qs |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
A L<App::ElasticSearch::Utilities::QueryString> object that contains the nested |
83
|
|
|
|
|
|
|
query. |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
=for Pod::Coverage handle_token |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
=head1 AUTHOR |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
Brad Lhotsky <brad@divisionbyzero.net> |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
This software is Copyright (c) 2023 by Brad Lhotsky. |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
This is free software, licensed under: |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
The (three-clause) BSD License |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
=cut |