Bug 30745: (follow-up) Rewritting the st-date-normalized test
The patch was corrupted, and was rewritten as the original one by Hammat Signed-off-by: Andrew Fuerste Henry <andrew@bywatersolutions.com> Signed-off-by: David Cook <dcook@prosentient.com.au> Signed-off-by: Katrin Fischer <katrin.fischer@bsz-bw.de>
This commit is contained in:
parent
6c0b557ea1
commit
2b19d59a1b
|
|
@ -855,6 +855,13 @@ sub _modify_string_by_type {
|
|||
$str = "[$from TO $until]";
|
||||
}
|
||||
}
|
||||
elsif($type eq 'st-date-normalized'){
|
||||
if ($str =~ /^(.*) - (.*)$/) {
|
||||
my $from = $1 || '*';
|
||||
my $until = $2 || '*';
|
||||
$str = "[$from TO $until]";
|
||||
}
|
||||
}
|
||||
return $str;
|
||||
}
|
||||
|
||||
|
|
@ -1098,7 +1105,6 @@ sub _fix_limit_special_cases {
|
|||
my ( $self, $limits ) = @_;
|
||||
|
||||
my @new_lim;
|
||||
my $ranges;
|
||||
foreach my $l (@$limits) {
|
||||
# This is set up by opac-search.pl
|
||||
if ( $l =~ /^yr,st-numeric,ge[=:]/ ) {
|
||||
|
|
@ -1166,15 +1172,11 @@ sub _fix_limit_special_cases {
|
|||
push @new_lim, $term;
|
||||
}
|
||||
}
|
||||
elsif ($l =~ /^acqdate,(ge|le),st-date-normalized=/ ) {
|
||||
my ($fromdate) = ( $l =~ /^acqdate,ge,st-date-normalized=(.*)$/ );
|
||||
my ($todate) = ( $l =~ /^acqdate,le,st-date-normalized=(.*)$/ );
|
||||
$fromdate ||= '*';
|
||||
$todate ||= '*';
|
||||
$ranges->{'date-of-acquisition.raw'} = {
|
||||
from => $fromdate,
|
||||
to => $todate
|
||||
}
|
||||
elsif ($l =~ /^acqdate,st-date-normalized=/ ) {
|
||||
my ($date) = ( $l =~ /^acqdate,st-date-normalized=(.*)$/ );
|
||||
next unless defined($date);
|
||||
$date = $self->_modify_string_by_type(type => 'st-date-normalized', operand => $date);
|
||||
push @new_lim, "date-of-acquisition.raw:$date";
|
||||
}
|
||||
else {
|
||||
my ( $field, $term ) = $l =~ /^\s*([\w,-]*?):(.*)/;
|
||||
|
|
@ -1186,12 +1188,6 @@ sub _fix_limit_special_cases {
|
|||
push @new_lim, $l;
|
||||
}
|
||||
}
|
||||
|
||||
if ( $ranges ) {
|
||||
foreach my $index ( keys %$ranges ) {
|
||||
push @new_lim, "$index:[$ranges->{$index}{from} TO $ranges->{$index}{to}]"
|
||||
}
|
||||
}
|
||||
}
|
||||
return \@new_lim;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -69,8 +69,7 @@ if ( $op eq "do_search" ) {
|
|||
{ index => $Koha::SearchEngine::BIBLIOS_INDEX } );
|
||||
|
||||
if (!@limits) {
|
||||
push(@limits, "acqdate,ge,st-date-normalized=$datefrom") if ($datefrom);
|
||||
push(@limits, "acqdate,le,st-date-normalized=$dateto") if ($dateto);
|
||||
push(@limits, "acqdate,st-date-normalized=$datefrom - $dateto");
|
||||
}
|
||||
|
||||
my ( $build_error, $query, $simple_query, $query_cgi,
|
||||
|
|
|
|||
|
|
@ -219,7 +219,7 @@ subtest 'build_authorities_query_compat() tests' => sub {
|
|||
};
|
||||
|
||||
subtest 'build_query tests' => sub {
|
||||
plan tests => 61;
|
||||
plan tests => 65;
|
||||
|
||||
my $qb;
|
||||
|
||||
|
|
@ -670,6 +670,38 @@ subtest 'build_query tests' => sub {
|
|||
is( $limit, '(author:("Dillinger Escaplan")) AND itype:(("BOOK") OR ("CD"))', "Limit formed correctly when no search terms");
|
||||
is( $limit_cgi,'&limit=author%3ADillinger%20Escaplan&limit=mc-itype%2Cphr%3ABOOK&limit=mc-itype%2Cphr%3ACD', "Limit CGI formed correctly when no search terms");
|
||||
is( $limit_desc,'(author:("Dillinger Escaplan")) AND itype:(("BOOK") OR ("CD"))',"Limit desc formed correctly when no search terms");
|
||||
|
||||
( undef, $query ) = $qb->build_query_compat( undef, ['barcode123123'], ['bc'],
|
||||
['acqdate,st-date-normalized= - '] );
|
||||
is(
|
||||
$query->{query}{query_string}{query},
|
||||
'(barcode:barcode123123) AND date-of-acquisition.raw:[* TO *]',
|
||||
'If no date all date-of-acquisition are selected'
|
||||
);
|
||||
|
||||
( undef, $query ) = $qb->build_query_compat( undef, ['barcode123123'], ['bc'],
|
||||
['acqdate,st-date-normalized=2024-08-01 - '] );
|
||||
is(
|
||||
$query->{query}{query_string}{query},
|
||||
'(barcode:barcode123123) AND date-of-acquisition.raw:[2024-08-01 TO *]',
|
||||
'Open start date in date range of an st-date-normalized search is handled properly'
|
||||
);
|
||||
|
||||
( undef, $query ) = $qb->build_query_compat( undef, ['barcode123123'], ['bc'],
|
||||
['acqdate,st-date-normalized= - 2024-08-30'] );
|
||||
is(
|
||||
$query->{query}{query_string}{query},
|
||||
'(barcode:barcode123123) AND date-of-acquisition.raw:[* TO 2024-08-30]',
|
||||
'Open end date in date range of an st-date-normalized search is handled properly'
|
||||
);
|
||||
|
||||
( undef, $query ) = $qb->build_query_compat( undef, ['barcode123123'], ['bc'],
|
||||
['acqdate,st-date-normalized=2024-08-01 - 2024-08-30'] );
|
||||
is(
|
||||
$query->{query}{query_string}{query},
|
||||
'(barcode:barcode123123) AND date-of-acquisition.raw:[2024-08-01 TO 2024-08-30]',
|
||||
'Date range in an st-date-normalized search is handled properly'
|
||||
);
|
||||
};
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue