sub _truncate_terms {
my ( $self, $query ) = @_;
- # '"donald duck" "the mouse" and peter" get split into
- # ['', '"donald duck"', '', ' ', '', '"the mouse"', '', ' ', 'and', ' ', 'pete']
- my @tokens = split /("[^"]+"|\s+)/, $query;
+ # '"donald duck" title:"the mouse" and peter" get split into
+ # ['', '"donald duck"', '', ' ', '', 'title:"the mouse"', '', ' ', 'and', ' ', 'pete']
+ my @tokens = split /((?:\w+:)?"[^"]+"|\s+)/, $query;
# Filter out empty tokens
my @words = grep { $_ !~ /^\s*$/ } @tokens;
# terminated by '*' and not a keyword
my @terms = map {
my $w = $_;
- (/^"/ or /\*$/ or grep {lc($w) eq $_} qw/and or not/) ? $_ : "$_*";
+ (/"$/ or /\*$/ or grep {lc($w) eq $_} qw/and or not/) ? $_ : "$_*";
} @words;
return join ' ', @terms;
};
subtest 'build_query tests' => sub {
- plan tests => 15;
+ plan tests => 16;
t::lib::Mocks::mock_preference('DisplayLibraryFacets','both');
my $query = $builder->build_query();
'(barcode:123456*)',
"query of specific field is truncated"
);
+
+ ( undef, $query ) = $builder->build_query_compat( undef, ['title:"donald duck"'] );
+ is(
+ $query->{query}{query_string}{query},
+ '(title:"donald duck")',
+ "query of specific field is not truncated when surrouned by quotes"
+ );
};