| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 38 | : ''; | ||||||||||||||||||||||||||||||||||||||||||
| 39 | } | ||||||||||||||||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||||||||||||||||
| 41 | # Check metadata for text type | ||||||||||||||||||||||||||||||||||||||||||
| 42 | 16 | ▶ | if ( exists $meta->{$f} | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%4/6
exists $meta->{$f} and exists $meta->{$f}{"type"} and $meta->{$f}{"type"} eq "text"
exists $meta->{$f} and exists $meta->{$f}{"type"}
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"
| |||||||||||||||||||||||||||||||||||||||||||
| 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
Condition66%2/3
not $matcher or $matcher eq "term"
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"
| |||||||||||||||||||||||||||||||||||||||||||
| 48 | } | ||||||||||||||||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||||||||||||||||
| 50 | 16 | ▶ | if( $matcher ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 51 | 7 | return { condition => { $matcher => { $f => $v } } }; | |||||||||||||||||||||||||||||||||||||||||
| 52 | } | ||||||||||||||||||||||||||||||||||||||||||
| 53 | } | ||||||||||||||||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||||||||||||||||
| 55 | 9 | return; | |||||||||||||||||||||||||||||||||||||||||
| 56 | } | ||||||||||||||||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||||||||||||||||
| 58 | # Return True; | ||||||||||||||||||||||||||||||||||||||||||
| 59 | 1 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||||||||||||||||
| 61 | __END__ | ||||||||||||||||||||||||||||||||||||||||||