From 8b2819ee14b2afe0a230793efe44c1e92a3678f3 Mon Sep 17 00:00:00 2001 From: Nick Clemens Date: Thu, 19 Oct 2023 11:49:26 +0000 Subject: [PATCH] Bug 35117: Improve consistency This patch improves the consistency between get_components_query and get_get_volumes_query methods so they both check for MARC21. Signed-off-by: Martin Renvoize --- Koha/Biblio.pm | 30 +++++++++++++++++------------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/Koha/Biblio.pm b/Koha/Biblio.pm index fc38955718c..28b71c87785 100644 --- a/Koha/Biblio.pm +++ b/Koha/Biblio.pm @@ -669,12 +669,15 @@ Returns a query which can be used to search for all component parts of MARC21 bi sub get_components_query { my ($self) = @_; - my $builder = Koha::SearchEngine::QueryBuilder->new( - { index => $Koha::SearchEngine::BIBLIOS_INDEX } ); + # MARC21 Only for now + return if ( C4::Context->preference('marcflavour') ne 'MARC21' ); + my $marc = $self->metadata->record; + + my $builder = Koha::SearchEngine::QueryBuilder->new( { index => $Koha::SearchEngine::BIBLIOS_INDEX } ); my $component_sort_field = C4::Context->preference('ComponentSortField') // "title"; my $component_sort_order = C4::Context->preference('ComponentSortOrder') // "asc"; - my $sort = $component_sort_field . "_" . $component_sort_order; + my $sort = $component_sort_field . "_" . $component_sort_order; my $searchstr; if ( C4::Context->preference('UseControlNumber') ) { @@ -685,11 +688,12 @@ sub get_components_query { my $pf003 = $marc->field('003') || undef; if ( !defined($pf003) ) { + # search for 773$w='Host001' - $searchstr .= "rcn:\"" . $pf001->data()."\""; - } - else { + $searchstr .= "rcn:\"" . $pf001->data() . "\""; + } else { $searchstr .= "("; + # search for (773$w='Host001' and 003='Host003') or 773$w='(Host003)Host001' $searchstr .= "(rcn:\"" . $pf001->data() . "\" AND cni:\"" . $pf003->data() . "\")"; $searchstr .= " OR rcn:\"" . $pf003->data() . " " . $pf001->data() . "\""; @@ -700,20 +704,20 @@ sub get_components_query { $searchstr .= " AND (bib-level:a OR bib-level:b)"; $searchstr .= ")"; } - } - else { - my $cleaned_title = $marc->subfield('245', "a"); + } else { + my $cleaned_title = $marc->subfield( '245', "a" ); $cleaned_title =~ tr|/||; $cleaned_title = $builder->clean_search_term($cleaned_title); - $searchstr = qq#Host-item:("$cleaned_title")#; + $searchstr = qq#Host-item:("$cleaned_title")#; + $searchstr .= " AND (bib-level:a OR bib-level:b)"; } - my ($error, $query ,$query_str) = $builder->build_query_compat( undef, [$searchstr], undef, undef, [$sort], 0 ); - if( $error ){ + my ( $error, $query, $query_str ) = $builder->build_query_compat( undef, [$searchstr], undef, undef, [$sort], 0 ); + if ($error) { warn $error; return; } - return ($query, $query_str, $sort); + return ( $query, $query_str, $sort ); } =head3 get_marc_volumes -- 2.41.0