From 52f94659c19268ccbc810f4dc254441c432e3d43 Mon Sep 17 00:00:00 2001 From: Kyle M Hall Date: Fri, 17 May 2024 06:51:32 -0400 Subject: [PATCH] Bug 34481: Tidy altered code Signed-off-by: Kyle M Hall Signed-off-by: Katrin Fischer --- Koha/Filter/MARC/EmbedSeeFromHeadings.pm | 30 +++++++------ Koha/SearchEngine/Elasticsearch.pm | 56 ++++++++++++++---------- misc/migration_tools/rebuild_zebra.pl | 8 ++-- 3 files changed, 53 insertions(+), 41 deletions(-) diff --git a/Koha/Filter/MARC/EmbedSeeFromHeadings.pm b/Koha/Filter/MARC/EmbedSeeFromHeadings.pm index 93eaf44501..4933b88745 100644 --- a/Koha/Filter/MARC/EmbedSeeFromHeadings.pm +++ b/Koha/Filter/MARC/EmbedSeeFromHeadings.pm @@ -86,13 +86,13 @@ include in facets, sorting, or suggestion fields) =cut sub fields { - my ($self, $record) = @_; + my ( $self, $record ) = @_; - my $params = $self->params; - my $other_headings = $params->{options}->{other_headings} || [ 'see_from' ]; + my $params = $self->params; + my $other_headings = $params->{options}->{other_headings} || ['see_from']; my @auth_others; - foreach my $other_heading ( @$other_headings ) { + foreach my $other_heading (@$other_headings) { if ( $other_heading eq 'see_from' ) { push @auth_others, '4..'; } @@ -101,7 +101,7 @@ sub fields { } } - my ($item_tag) = GetMarcFromKohaField( "items.itemnumber" ); + my ($item_tag) = GetMarcFromKohaField("items.itemnumber"); $item_tag ||= ''; my @newfields; @@ -114,21 +114,23 @@ sub fields { my $authority = Koha::MetadataRecord::Authority->get_from_authid($authid); next unless $authority; - my $auth_marc = $authority->record; + my $auth_marc = $authority->record; my @authfields = $auth_marc->field(@auth_others); foreach my $authfield (@authfields) { - my $tag = substr($field->tag(), 0, 1) . substr($authfield->tag(), 1, 2); + my $tag = substr( $field->tag(), 0, 1 ) . substr( $authfield->tag(), 1, 2 ); next if MARC::Field->is_controlfield_tag($tag); - my $newfield = MARC::Field->new($tag, - 'z', - $authfield->indicator(2) || ' ', - '9' => '1'); - foreach my $sub ($authfield->subfields()) { - my ($code,$val) = @$sub; + my $newfield = MARC::Field->new( + $tag, + 'z', + $authfield->indicator(2) || ' ', + '9' => '1' + ); + foreach my $sub ( $authfield->subfields() ) { + my ( $code, $val ) = @$sub; $newfield->add_subfields( $code => $val ); } $newfield->delete_subfield( code => '9' ); - push @newfields, $newfield if (scalar($newfield->subfields()) > 0); + push @newfields, $newfield if ( scalar( $newfield->subfields() ) > 0 ); } } diff --git a/Koha/SearchEngine/Elasticsearch.pm b/Koha/SearchEngine/Elasticsearch.pm index b7359f5f47..af9bdd97a1 100644 --- a/Koha/SearchEngine/Elasticsearch.pm +++ b/Koha/SearchEngine/Elasticsearch.pm @@ -664,7 +664,12 @@ sub marc_records_to_documents { } } - if ( $self->index eq $BIBLIOS_INDEX and ( C4::Context->preference('IncludeSeeFromInSearches') || C4::Context->preference('IncludeSeeAlsoFromInSearches') ) ) { + if ( + $self->index eq $BIBLIOS_INDEX + and ( C4::Context->preference('IncludeSeeFromInSearches') + || C4::Context->preference('IncludeSeeAlsoFromInSearches') ) + ) + { my $marc_filter = Koha::Filter::MARC::EmbedSeeFromHeadings->new; my @other_headings; if ( C4::Context->preference('IncludeSeeFromInSearches') ) { @@ -673,30 +678,29 @@ sub marc_records_to_documents { if ( C4::Context->preference('IncludeSeeAlsoFromInSearches') ) { push @other_headings, 'see_also_from'; } - $marc_filter->initialize( - { - options => { - other_headings => \@other_headings - } - } - ); - foreach my $field ($marc_filter->fields($record)) { - my $data_field_rules = $data_fields_rules->{$field->tag()}; + $marc_filter->initialize( { options => { other_headings => \@other_headings } } ); + foreach my $field ( $marc_filter->fields($record) ) { + my $data_field_rules = $data_fields_rules->{ $field->tag() }; if ($data_field_rules) { my $subfields_mappings = $data_field_rules->{subfields}; - my $wildcard_mappings = $subfields_mappings->{'*'}; - foreach my $subfield ($field->subfields()) { - my ($code, $data) = @{$subfield}; + my $wildcard_mappings = $subfields_mappings->{'*'}; + foreach my $subfield ( $field->subfields() ) { + my ( $code, $data ) = @{$subfield}; my @mappings; push @mappings, @{ $subfields_mappings->{$code} } if $subfields_mappings->{$code}; - push @mappings, @$wildcard_mappings if $wildcard_mappings; + push @mappings, @$wildcard_mappings if $wildcard_mappings; + # Do not include "see from" into these kind of fields @mappings = grep { $_->[0] !~ /__(sort|facet|suggestion)$/ } @mappings; if (@mappings) { - $self->_process_mappings(\@mappings, $data, $record_document, { + $self->_process_mappings( + \@mappings, + $data, + $record_document, + { data_source => 'subfield', - code => $code, - field => $field + code => $code, + field => $field } ); } @@ -704,19 +708,25 @@ sub marc_records_to_documents { my $subfields_join_mappings = $data_field_rules->{subfields_join}; if ($subfields_join_mappings) { - foreach my $subfields_group (keys %{$subfields_join_mappings}) { + foreach my $subfields_group ( keys %{$subfields_join_mappings} ) { my $data_field = $field->clone; + # remove empty subfields, otherwise they are printed as a space - $data_field->delete_subfield(match => qr/^$/); - my $data = $data_field->as_string( $subfields_group ); + $data_field->delete_subfield( match => qr/^$/ ); + my $data = $data_field->as_string($subfields_group); if ($data) { my @mappings = @{ $subfields_join_mappings->{$subfields_group} }; + # Do not include "see from" into these kind of fields @mappings = grep { $_->[0] !~ /__(sort|facet|suggestion)$/ } @mappings; - $self->_process_mappings(\@mappings, $data, $record_document, { + $self->_process_mappings( + \@mappings, + $data, + $record_document, + { data_source => 'subfields_group', - codes => $subfields_group, - field => $field + codes => $subfields_group, + field => $field } ); } diff --git a/misc/migration_tools/rebuild_zebra.pl b/misc/migration_tools/rebuild_zebra.pl index 941c5f8e2f..eccb9349a4 100755 --- a/misc/migration_tools/rebuild_zebra.pl +++ b/misc/migration_tools/rebuild_zebra.pl @@ -662,7 +662,9 @@ sub get_corrected_marc_record { my @filters; my @other_headings; push @filters, 'EmbedItemsAvailability'; - if ( C4::Context->preference('IncludeSeeFromInSearches') || C4::Context->preference('IncludeSeeAlsoFromInSearches') ){ + if ( C4::Context->preference('IncludeSeeFromInSearches') + || C4::Context->preference('IncludeSeeAlsoFromInSearches') ) + { push @filters, 'EmbedSeeFromHeadings'; if ( C4::Context->preference('IncludeSeeFromInSearches') ) { push @other_headings, 'see_from'; @@ -675,9 +677,7 @@ sub get_corrected_marc_record { my $normalizer = Koha::RecordProcessor->new( { filters => \@filters, - options => { - other_headings => \@other_headings - } + options => { other_headings => \@other_headings } } ); $marc = $normalizer->process($marc); -- 2.39.5