Bug 19575: Rebase and fix tests

This patch lower cases the sort by fields to normalize checking them and adjusts
some existing tests to meet the new expectations.

The regex for splitting terms has been moved into a subroutine so that adjustment was made

Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>

Signed-off-by: Nick Clemens <nick@bywatersolutions.com>
(cherry picked from commit c2061adc8b)
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
This commit is contained in:
root 2019-02-12 21:52:39 +00:00 committed by Martin Renvoize
parent 68b129e0c4
commit ce578a9aca
No known key found for this signature in database
GPG Key ID: 422B469130441A0F
2 changed files with 9 additions and 7 deletions

View File

@ -432,6 +432,7 @@ sub build_authorities_query_compat {
# Convert to lower case
$marclist = [map(lc, @{$marclist})];
$orderby = lc $orderby;
# Make sure everything exists
foreach my $m (@$marclist) {
@ -454,7 +455,7 @@ sub build_authorities_query_compat {
: ( $orderby =~ /^auth/ ) ? 'local-number'
: undef;
if ($sort_field) {
my $sort_order = ( $orderby =~ /Asc$/ ) ? 'asc' : 'desc';
my $sort_order = ( $orderby =~ /asc$/ ) ? 'asc' : 'desc';
%sort = ( $sort_field => $sort_order, );
}
my %search = (
@ -887,7 +888,6 @@ operands and double quoted strings.
=cut
my $tokenize_split_re = qr/((?:${field_name_pattern}${multi_field_pattern}:)?"[^"]+"|\s+)/;
sub _truncate_terms {
my ( $self, $query ) = @_;
@ -914,12 +914,14 @@ any field prefixes and quoted strings.
=cut
my $tokenize_split_re = qr/((?:${field_name_pattern}${multi_field_pattern}:)?"[^"]+"|\s+)/;
sub _split_query {
my ( $self, $query ) = @_;
# '"donald duck" title:"the mouse" and peter" get split into
# ['', '"donald duck"', '', ' ', '', 'title:"the mouse"', '', ' ', 'and', ' ', 'pete']
my @tokens = split /((?:[\w\-.]+:)?"[^"]+"|\s+)/, $query;
my @tokens = split $tokenize_split_re, $query;
# Filter out empty values
@tokens = grep( /\S/, @tokens );

View File

@ -144,7 +144,7 @@ subtest 'build_authorities_query_compat() tests' => sub {
$query->{sort},
[
{
'Heading__sort.phrase' => 'asc'
'heading__sort' => 'asc'
}
],
"ascending sort parameter properly formed"
@ -154,7 +154,7 @@ subtest 'build_authorities_query_compat() tests' => sub {
$query->{sort},
[
{
'Heading__sort.phrase' => 'desc'
'heading__sort' => 'desc'
}
],
"descending sort parameter properly formed"
@ -428,7 +428,7 @@ subtest "_convert_sort_fields() tests" => sub {
is_deeply(
\@sort_by,
[
{ field => 'callnum', direction => 'asc' },
{ field => 'local-classification', direction => 'asc' },
{ field => 'author', direction => 'desc' }
],
'sort fields should have been split correctly'
@ -439,7 +439,7 @@ subtest "_convert_sort_fields() tests" => sub {
is_deeply(
\@sort_by,
[
{ field => 'callnum', direction => 'asc' },
{ field => 'local-classification', direction => 'asc' },
{ field => 'author', direction => 'desc' }
],
'sort fields should have been split correctly'