App-ElasticSearch-Utilities
view release on metacpan or search on metacpan
lib/App/ElasticSearch/Utilities/QueryString/Text.pm view on Meta::CPAN
package App::ElasticSearch::Utilities::QueryString::Text;
# ABSTRACT: Provides a better interface for text and keyword queries
use v5.16;
use warnings;
our $VERSION = '8.8'; # VERSION
use CLI::Helpers qw(:output);
use Const::Fast;
use namespace::autoclean;
use Moo;
with 'App::ElasticSearch::Utilities::QueryString::Plugin';
sub _build_priority { 4; }
sub handle_token {
my ($self,$token) = @_;
my $meta = $self->fields_meta;
debug(sprintf "%s - evaluating token '%s'", $self->name, $token);
if ( $token =~ /[^:]+:/ ) {
my ($f,$v) = split /:/, $token, 2;
my $matcher = '';
# Grab the prefix symbol
$f =~ s/^(?<op>[^a-zA-Z])//;
if( $+{op} ) {
$matcher = $+{op} eq '*' ? 'wildcard'
: $+{op} eq '=' ? 'term'
: $+{op} eq '/' ? 'regexp'
: $+{op} eq '~' ? 'fuzzy'
: $+{op} eq '+' ? 'match_phrase'
: '';
}
# Check metadata for text type
if ( exists $meta->{$f}
&& exists $meta->{$f}{type}
&& $meta->{$f}{type} eq 'text'
) {
# We can't use term filters on text fields
$matcher = 'match' if !$matcher or $matcher eq 'term';
}
if( $matcher ) {
return { condition => { $matcher => { $f => $v } } };
}
}
return;
}
# Return True;
1;
__END__
=pod
=head1 NAME
App::ElasticSearch::Utilities::QueryString::Text - Provides a better interface for text and keyword queries
=head1 VERSION
version 8.8
( run in 0.959 second using v1.01-cache-2.11-cpan-39bf76dae61 )