Bug 30745: (QA follow-up) tidy

Signed-off-by: David Cook <dcook@prosentient.com.au>
Signed-off-by: Katrin Fischer <katrin.fischer@bsz-bw.de>
This commit is contained in:
David Cook 2024-11-14 05:44:59 +00:00 committed by Katrin Fischer
parent 2b19d59a1b
commit 425af8aaad
Signed by: kfischer
GPG key ID: 0EF6E2C03357A834
3 changed files with 42 additions and 38 deletions

View file

@ -854,10 +854,9 @@ sub _modify_string_by_type {
my $until = $2 || '*';
$str = "[$from TO $until]";
}
}
elsif($type eq 'st-date-normalized'){
if ($str =~ /^(.*) - (.*)$/) {
my $from = $1 || '*';
} elsif ( $type eq 'st-date-normalized' ) {
if ( $str =~ /^(.*) - (.*)$/ ) {
my $from = $1 || '*';
my $until = $2 || '*';
$str = "[$from TO $until]";
}
@ -1171,11 +1170,10 @@ sub _fix_limit_special_cases {
else {
push @new_lim, $term;
}
}
elsif ($l =~ /^acqdate,st-date-normalized=/ ) {
} 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);
$date = $self->_modify_string_by_type( type => 'st-date-normalized', operand => $date );
push @new_lim, "date-of-acquisition.raw:$date";
}
else {

View file

@ -40,7 +40,7 @@ my $query = CGI->new;
my $type = $query->param('type');
my $op = $query->param('op') || '';
my $batch_id = $query->param('batch_id');
my @limits = split(" AND ", $query->param('limits') || "");
my @limits = split( " AND ", $query->param('limits') || "" );
my $startfrom = $query->param('startfrom') || 1;
my ($template, $loggedinuser, $cookie) = (undef, undef, undef);
my (
@ -63,33 +63,31 @@ if ( $op eq "do_search" ) {
$datefrom = $query->param('datefrom');
$dateto = $query->param('dateto');
my $builder = Koha::SearchEngine::QueryBuilder->new(
{ index => $Koha::SearchEngine::BIBLIOS_INDEX } );
my $searcher = Koha::SearchEngine::Search->new(
{ index => $Koha::SearchEngine::BIBLIOS_INDEX } );
my $builder = Koha::SearchEngine::QueryBuilder->new( { index => $Koha::SearchEngine::BIBLIOS_INDEX } );
my $searcher = Koha::SearchEngine::Search->new( { index => $Koha::SearchEngine::BIBLIOS_INDEX } );
if (!@limits) {
push(@limits, "acqdate,st-date-normalized=$datefrom - $dateto");
if ( !@limits ) {
push( @limits, "acqdate,st-date-normalized=$datefrom - $dateto" );
}
my ( $build_error, $query, $simple_query, $query_cgi,
$query_desc, $limit, $limit_cgi, $limit_desc,
$query_type )
= $builder->build_query_compat( undef, [$ccl_textbox], [$idx], \@limits);
my (
$build_error, $query, $simple_query, $query_cgi,
$query_desc, $limit, $limit_cgi, $limit_desc,
$query_type
) = $builder->build_query_compat( undef, [$ccl_textbox], [$idx], \@limits );
my $offset = $startfrom > 1 ? $startfrom - 1 : 0;
my ( $error, $results, $facets ) = $searcher->search_compat(
$query, $simple_query, [], ['biblioserver'], $resultsperpage, $offset,
undef, undef, $query_type, undef
$query, $simple_query, [], ['biblioserver'], $resultsperpage, $offset,
undef, undef, $query_type, undef
);
if (!defined $error && defined($results) && @{$results->{biblioserver}{RECORDS}} > 0 ) {
$show_results = grep { defined $_ } @{$results->{biblioserver}{RECORDS}};
$marcresults = [ grep { defined $_ } @{$results->{biblioserver}{RECORDS}} ];
$total_hits = $results->{biblioserver}{hits};
}
else {
if ( !defined $error && defined($results) && @{ $results->{biblioserver}{RECORDS} } > 0 ) {
$show_results = grep { defined $_ } @{ $results->{biblioserver}{RECORDS} };
$marcresults = [ grep { defined $_ } @{ $results->{biblioserver}{RECORDS} } ];
$total_hits = $results->{biblioserver}{hits};
} else {
Koha::Logger->get->warn("ERROR label-item-search: no results from simple_search_compat");
# leave $show_results undef
@ -192,13 +190,13 @@ if ($show_results) {
);
$template->param(
results => ($show_results ? 1 : 0),
results => ( $show_results ? 1 : 0 ),
result_set => \@results_set,
batch_id => $batch_id,
type => $type,
idx => $idx,
ccl_textbox => $ccl_textbox,
limits => join(" AND ", @limits),
limits => join( " AND ", @limits ),
);
}

View file

@ -671,34 +671,42 @@ subtest 'build_query tests' => sub {
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= - '] );
( 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 - '] );
( 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'] );
( 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},
( 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'
);