Bug 15187: Index 880 in Zebra the same as Elasticsearch

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 <david@davidnind.com>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
This commit is contained in:
David Cook 2022-05-02 07:34:34 +00:00 committed by Tomas Cohen Arazi
parent 87aa05f9de
commit 85690a14f8
No known key found for this signature in database
GPG Key ID: 0A272EA1B2F3C15F
2 changed files with 89 additions and 0 deletions

View File

@ -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 <http://www.gnu.org/licenses>.
=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;

View File

@ -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);