From 2d2da75188189ee192105b23dcfba4c48fc4bc14 Mon Sep 17 00:00:00 2001 From: Lari Taskula Date: Fri, 18 Oct 2024 21:04:44 +0000 Subject: [PATCH] Bug 15728: Zebra - Support component records limit To test: Apply all patches from this Bug Execute steps 5-15 both in staff client and OPAC 1. prove t/db_dependent/Search.t 2. Set system preferences SearchEngine = Zebra ShowComponentRecordsFacet = both staff interface and OPAC 3. Create a new record (leader/7 should NOT be "a" nor "b") 4. Create two new component records (leader/7 should be "a" or "b") 5. Search catalog with allrecords,AlwaysMatches="" 6. Observe facets containing category "Component records" 7. Note down total number of search results (referred as ALL) 8. From facets, click "Limit to component records" 9. Note down total number of component record results (referred as COMP) 10. From search results, observe your newly created component records 11. From facets under Component records, click "Show all records" 12. Observe number of search results equal to ALL 13. From facets, click "Exclude component records" 14. Observe total number of search results being ALL-COMP 15. Observe your newly created component records not part of results --- C4/Search.pm | 20 ++++++++++++++++---- t/db_dependent/Search.t | 14 +++++++++++++- 2 files changed, 29 insertions(+), 5 deletions(-) diff --git a/C4/Search.pm b/C4/Search.pm index ca8e79ab0f..ce8561c53f 100644 --- a/C4/Search.pm +++ b/C4/Search.pm @@ -1244,7 +1244,8 @@ sub buildQuery { # add limits my %group_OR_limits; - my $availability_limit; + my ( $availability_limit, $component_records_limit, $host_records_limit ); + my $component_records_query = "( Bib-level='a' or Bib-level='b' )"; foreach my $this_limit (@limits) { next unless $this_limit; if ( $this_limit =~ /available/ ) { @@ -1257,7 +1258,16 @@ sub buildQuery { $limit_cgi .= "&limit=available"; $limit_desc .= ""; } + elsif ( $this_limit =~ /^component_records$/ ) { + $component_records_limit .= "$component_records_query"; + $limit_cgi .= "&limit=component_records"; + $limit_desc .= ""; + } elsif ( $this_limit =~ /^exclude_component_records$/ ) { + $host_records_limit .= "( (allrecords,AlwaysMatches='') not $component_records_query )"; + $limit_cgi .= "&limit=exclude_component_records"; + $limit_desc .= ""; + } # group_OR_limits, prefixed by mc- # OR every member of the group elsif ( $this_limit =~ /mc/ ) { @@ -1330,9 +1340,11 @@ sub buildQuery { $limit .= " and " if ( $query || $limit ); $limit .= "($group_OR_limits{$k})"; } - if ($availability_limit) { - $limit .= " and " if ( $query || $limit ); - $limit .= "($availability_limit)"; + foreach my $l ( $availability_limit, $component_records_limit, $host_records_limit ) { + if ($l) { + $limit .= " and " if ( $query || $limit ); + $limit .= "($l)"; + } } # for handling ccl, cql, pqf queries in diagnostic mode, skip the rest of the steps diff --git a/t/db_dependent/Search.t b/t/db_dependent/Search.t index 00ce65abda..afdf656229 100755 --- a/t/db_dependent/Search.t +++ b/t/db_dependent/Search.t @@ -661,6 +661,18 @@ ok(MARC::Record::new_from_xml($results_hashref->{biblioserver}->{RECORDS}->[0],' is( $query, "an:42 and (( (allrecords,AlwaysMatches='') and (not-onloan-count,st-numeric >= 1) and (lost,st-numeric=0) ))", 'buildQuery should add the available part to the query if requested with ccl' ); is( $query_desc, 'an:42', 'buildQuery should remove the available part from the query' ); + ( $error, $query, $simple_query, $query_cgi, + $query_desc, $limit, $limit_cgi, $limit_desc, + $query_type ) = buildQuery([], [ 'ccl=an:42' ], [], ['component_records'], [], 0, 'en'); + is( $query, "an:42 and (( Bib-level='a' or Bib-level='b' ))", 'buildQuery should add the component_records part to the query if requested with ccl' ); + is( $query_desc, 'an:42', 'buildQuery should remove the component_records part from the query' ); + + ( $error, $query, $simple_query, $query_cgi, + $query_desc, $limit, $limit_cgi, $limit_desc, + $query_type ) = buildQuery([], [ 'ccl=an:42' ], [], ['exclude_component_records'], [], 0, 'en'); + is( $query, "an:42 and (( (allrecords,AlwaysMatches='') not ( Bib-level='a' or Bib-level='b' ) ))", 'buildQuery should add the exclude_component_records part to the query if requested with ccl' ); + is( $query_desc, 'an:42', 'buildQuery should remove the exclude_component_records part from the query' ); + ( $error, $query, $simple_query, $query_cgi, $query_desc, $limit, $limit_cgi, $limit_desc, $query_type ) = buildQuery([], [ 'ccl=an:42' ], [], ['branch:CPL'], [], 0, 'en'); @@ -923,7 +935,7 @@ sub run_unimarc_search_tests { } subtest 'MARC21 + DOM' => sub { - plan tests => 93; + plan tests => 97; run_marc21_search_tests(); }; -- 2.34.1