From db8f7b0a7d2462fca0310f191ce862243b272e57 Mon Sep 17 00:00:00 2001 From: David Cook Date: Mon, 2 May 2022 07:34:34 +0000 Subject: [PATCH] Bug 15187: Index 880 in Zebra the same as Elasticsearch MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This patch modifies the MARC21 export to Zebra, so that 880 fields are rewritten as their linked fields, in the same way that we already do with Elasticsearch, so that the alternate graphic representation of fields are indexed accordingly. (ie 880 $6245-01 Chinese titles will be indexed into the title index using the 245 rules) Test plan: 0. Apply patch 1. Turn on ICU indexing 1b. vi /etc/koha/zebradb/etc/default.idx 1c. Replace charmap word-phrase-utf.chr with icuchain words-icu.xml 1d. Replace charmap word-phrase-utf.chr with icuchain phrases-icu.xml 1e. Restart Zebra server 1f. Re-index Zebra 2. Add record with a 880 $6 245-01 $a 教牧書信 field. 3. Search for this record using a title index with the Chinese title 4. Note that the record is correctly retrieved (Note: This test probably works better using author or series as they present as links on the detail page which makes the fix more obviously useful.) Signed-off-by: David Nind Signed-off-by: Martin Renvoize --- Koha/Filter/MARC/Index880InZebra.pm | 88 +++++++++++++++++++++++++++ misc/migration_tools/rebuild_zebra.pl | 1 + 2 files changed, 89 insertions(+) create mode 100644 Koha/Filter/MARC/Index880InZebra.pm diff --git a/Koha/Filter/MARC/Index880InZebra.pm b/Koha/Filter/MARC/Index880InZebra.pm new file mode 100644 index 0000000000..0cff55c117 --- /dev/null +++ b/Koha/Filter/MARC/Index880InZebra.pm @@ -0,0 +1,88 @@ +package Koha::Filter::MARC::Index880InZebra; + +# This file is part of Koha. +# +# Koha is free software; you can redistribute it and/or modify it +# under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# Koha is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with Koha; if not, see . + +=head1 NAME + +Koha::Filter::MARC::Index880InZebra - replace 880 with its linked field number +so that the alternate graphic representation gets indexed appropriately +(see Koha::SearchEngine::Elasticsearch for the ES version) + +=head1 SYNOPSIS + +my $processor = Koha::RecordProcessor->new({ filters => ('Index880InZebra') }); + +=head1 DESCRIPTION + +Filter to rewrite 880 to linked field + +=cut + +use Modern::Perl; + +use C4::Context; + +use base qw(Koha::RecordProcessor::Base); +our $NAME = 'Index880InZebra'; + +our $marcflavour = lc C4::Context->preference('marcflavour'); + +=head2 filter + + my $newrecord = $filter->filter($record); + my $newrecords = $filter->filter(\@records); + +=cut + +sub filter { + my $self = shift; + my $record = shift; + my $newrecord; + + return unless defined $record; + + if (ref $record eq 'ARRAY') { + my @recarray; + foreach my $thisrec (@$record) { + push @recarray, _processrecord($thisrec); + } + $newrecord = \@recarray; + } elsif (ref $record eq 'MARC::Record') { + $newrecord = _processrecord($record); + } + + return $newrecord; +} + +sub _processrecord { + + my $record = shift; + if ($marcflavour && $marcflavour eq 'marc21'){ + my @fields = $record->field('880'); + foreach my $field (@fields){ + my $sub6 = $field->subfield('6'); + if ($sub6 =~ /^(...)-\d+/) { + my $tag = $1; + if ($tag){ + $field->set_tag($tag); + } + } + } + } + return $record; +} + +1; diff --git a/misc/migration_tools/rebuild_zebra.pl b/misc/migration_tools/rebuild_zebra.pl index 718c30533d..2263bfd0f9 100755 --- a/misc/migration_tools/rebuild_zebra.pl +++ b/misc/migration_tools/rebuild_zebra.pl @@ -661,6 +661,7 @@ sub get_corrected_marc_record { push @filters, 'EmbedItemsAvailability'; push @filters, 'EmbedSeeFromHeadings' if C4::Context->preference('IncludeSeeFromInSearches'); + push @filters, 'Index880InZebra'; my $normalizer = Koha::RecordProcessor->new( { filters => \@filters } ); $marc = $normalizer->process($marc); -- 2.20.1