Bug 18374: (QA follow-up) Fix auto truncation for field:"value"

Signed-off-by: Julian Maurice <julian.maurice@biblibre.com>

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
(cherry picked from commit c991ac6b61)
Signed-off-by: Fridolin Somers <fridolin.somers@biblibre.com>
This commit is contained in:
Julian Maurice 2017-10-13 10:05:08 +00:00 committed by Fridolin Somers
parent 1edf743c90
commit e1fa378ec5
2 changed files with 12 additions and 5 deletions

View File

@ -795,9 +795,9 @@ operands and double quoted strings.
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;
@ -806,7 +806,7 @@ sub _truncate_terms {
# 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;

View File

@ -96,7 +96,7 @@ subtest 'json2marc' => sub {
};
subtest 'build_query tests' => sub {
plan tests => 15;
plan tests => 16;
t::lib::Mocks::mock_preference('DisplayLibraryFacets','both');
my $query = $builder->build_query();
@ -186,5 +186,12 @@ subtest 'build_query tests' => sub {
'(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"
);
};