lib/App/ElasticSearch/Utilities/QueryString/Text.pm

filter: Statementstmt 100% 35 / 35 Branchbran 90.0% 18 / 20 Conditioncond 66.6% 6 / 9 MC/DCmcdc 20.0% 1 / 5 Subroutinesub 100% 8 / 8 Podpod 0.0% 0 / 1 totaltotal 87.1% 68 / 78 CC 14 SCAR 22.9
CC
14
Cov
92%
handle_token
14.3
BEGIN
1.0
BEGIN
1.0
CRAP 9.9
« script/es-status.pl ↑ Summary lib/App/ElasticSearch/Utilities/VersionHacks.pm »
1 package App::ElasticSearch::Utilities::QueryString::Text;
2 # ABSTRACT: Provides a better interface for text and keyword queries
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 Const::Fast;
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 1 ▶sub _build_priority { 4; }
Subroutine _build_priority: called CC=1 SCAR=0.0
17  
18  
19 16 ▶sub handle_token {
Subroutine handle_token: called CC=14 SCAR=26.6
Pod undocumented
20 16 my ($self,$token) = @_;
21  
22 16 my $meta = $self->fields_meta;
23  
24 16 debug(sprintf "%s - evaluating token '%s'", $self->name, $token);
25 16 ▶ if ( $token =~ /[^:]+:/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($token =~ /[^:]+:/u) 16 0 16
26 16 my ($f,$v) = split /:/, $token, 2;
27  
28 16 my $matcher = '';
29  
30 # Grab the prefix symbol
31 16 $f =~ s/^(?<op>[^a-zA-Z])//;
32 16 ▶ if( $+{op} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($+{"op"}) 8 8 16
33 $matcher = $+{op} eq '*' ? 'wildcard'
34 : $+{op} eq '=' ? 'term'
35 : $+{op} eq '/' ? 'regexp'
36 : $+{op} eq '~' ? 'fuzzy'
37 8 ▶ : $+{op} eq '+' ? 'match_phrase'
Branch: 5 branches
BranchTrueFalseTotal
$+{'op'} eq '*' ? : 1 7 8
$+{'op'} eq '=' ? : 2 5 7
$+{'op'} eq '/' ? : 1 4 5
$+{'op'} eq '~' ? : 1 3 4
$+{'op'} eq '+' ? : 1 2 3
38 : '';
39 }
40  
41 # Check metadata for text type
42 16 ▶ if ( exists $meta->{$f}
Branch: 1 branch
BranchTrueFalseTotal
if (exists $meta->{$f} and exists $meta->{$f}{"type"} and $meta->{$f}{"type"} eq "text") 2 14 16
Condition66%4/6
exists $meta->{$f} and exists $meta->{$f}{"type"} and $meta->{$f}{"type"} eq "text"
!ll&&!rl&&r
1402
exists $meta->{$f} and exists $meta->{$f}{"type"}
!ll&&!rl&&r
1402
MC/DC33%1/3
exists $meta->{$f} and exists $meta->{$f}{"type"} and $meta->{$f}{"type"} eq "text"
exists $meta->{$f} exists $meta->{$f}{"type"} $meta->{$f}{"type"} eq "text"
Truth table50%2/4
A and B and C
A= exists $meta->{$f}B= exists $meta->{$f}{"type"}C= $meta->{$f}{"type"} eq "text"
ABCresult
0XX0
10X0
1100
1111
43 && exists $meta->{$f}{type}
44 && $meta->{$f}{type} eq 'text'
45 ) {
46 # We can't use term filters on text fields
47 2 ▶ $matcher = 'match' if !$matcher or $matcher eq 'term';
Branch: 1 branch
BranchTrueFalseTotal
if not $matcher or $matcher eq "term" 2 0 2
Condition66%2/3
not $matcher or $matcher eq "term"
l!l&&r!l&&!r
110
MC/DC0%0/2
not $matcher or $matcher eq "term"
not $matcher $matcher eq "term"
Truth table66%2/3
not(A) or B
A= not $matcherB= $matcher eq "term"
ABresult
1X1
011
000
48 }
49  
50 16 ▶ if( $matcher ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($matcher) 7 9 16
51 7 return { condition => { $matcher => { $f => $v } } };
52 }
53 }
54  
55 9 return;
56 }
57  
58 # Return True;
59 1 1;
60  
61 __END__
« script/es-status.pl ↑ Summary lib/App/ElasticSearch/Utilities/VersionHacks.pm »