View | Details | Raw Unified | Return to bug 36884
Collapse All | Expand All

(-)a/Koha/Filter/MARC/EmbedRecordSource.pm (+105 lines)
Line 0 Link Here
1
package Koha::Filter::MARC::EmbedRecordSource;
2
3
# Copyright 2024 BibLibre
4
#
5
# This file is part of Koha.
6
#
7
# Koha is free software; you can redistribute it and/or modify it
8
# under the terms of the GNU General Public License as published by
9
# the Free Software Foundation; either version 3 of the License, or
10
# (at your option) any later version.
11
#
12
# Koha is distributed in the hope that it will be useful, but
13
# WITHOUT ANY WARRANTY; without even the implied warranty of
14
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
# GNU General Public License for more details.
16
#
17
# You should have received a copy of the GNU General Public License
18
# along with Koha; if not, see <http://www.gnu.org/licenses>.
19
20
=head1 NAME
21
22
Koha::Filter::MARC::EmbedRecordSource - embeds record source into MARC for indexing
23
24
=head1 SYNOPSIS
25
26
27
=head1 DESCRIPTION
28
29
Filter to embed record source into MARC records.
30
31
=cut
32
33
use strict;
34
use warnings;
35
use Koha::Biblios;
36
37
use base qw(Koha::RecordProcessor::Base);
38
our $NAME = 'EmbedRecordSource';
39
40
=head2 filter
41
42
    my $newrecord = $filter->filter($record);
43
    my $newrecords = $filter->filter(\@records);
44
45
Embed see from headings into the specified record(s) and return the result.
46
In order to differentiate added headings from actual headings, a 'z' is
47
put in the first indicator.
48
49
=cut
50
sub filter {
51
    my $self = shift;
52
    my $record = shift;
53
    my $newrecord;
54
55
    return unless defined $record;
56
57
    if (ref $record eq 'ARRAY') {
58
        my @recarray;
59
        foreach my $thisrec (@$record) {
60
            push @recarray, $self->_processrecord($thisrec);
61
        }
62
        $newrecord = \@recarray;
63
    } elsif (ref $record eq 'MARC::Record') {
64
        $newrecord = $self->_processrecord($record);
65
    }
66
67
    return $newrecord;
68
}
69
70
sub _processrecord {
71
    my ($self, $record) = @_;
72
73
    $record->append_fields($self->fields($record));
74
75
    return $record;
76
}
77
78
=head2 fields
79
80
    my @fields = $filter->fields($record);
81
82
Retrieve the fields that would be embedded if the record were processed by the filter.
83
Used during Elasticsearch indexing to give special treatment to these field (i.e. don't
84
include in facets, sorting, or suggestion fields)
85
86
=cut
87
sub fields {
88
    my ($self, $record) = @_;
89
    my @newfield;
90
    
91
    my $biblionumber = $record->field('999')->subfield('c');
92
    return @newfield unless $biblionumber;
93
94
    my $biblio = Koha::Biblios->find($biblionumber);
95
    return @newfield unless $biblio;
96
    
97
    my $source = $biblio->metadata->record_source;
98
    return @newfield unless $source;
99
100
    my $marc_source = MARC::Field->new('942', 'z', ' ', 'z' => $source->name );
101
    push @newfield, $marc_source if (scalar($marc_source->subfields()) > 0);
102
    return @newfield;
103
}
104
105
1;
(-)a/Koha/SearchEngine/Elasticsearch.pm (+23 lines)
Lines 25-30 use Koha::Database; Link Here
25
use Koha::Exceptions::Config;
25
use Koha::Exceptions::Config;
26
use Koha::Exceptions::Elasticsearch;
26
use Koha::Exceptions::Elasticsearch;
27
use Koha::Filter::MARC::EmbedSeeFromHeadings;
27
use Koha::Filter::MARC::EmbedSeeFromHeadings;
28
use Koha::Filter::MARC::EmbedRecordSource;
28
use Koha::SearchFields;
29
use Koha::SearchFields;
29
use Koha::SearchMarcMaps;
30
use Koha::SearchMarcMaps;
30
use Koha::Caches;
31
use Koha::Caches;
Lines 664-669 sub marc_records_to_documents { Link Here
664
            }
665
            }
665
        }
666
        }
666
667
668
        if ( Koha::RecordSources->count() and $self->index eq 'biblios') {
669
            foreach my $field (Koha::Filter::MARC::EmbedRecordSource->new->fields($record)) {
670
                my $data_field_rules = $data_fields_rules->{$field->tag()};
671
                if ($data_field_rules) {
672
                    my $subfields_mappings = $data_field_rules->{subfields};
673
                    foreach my $subfield ($field->subfields()) {
674
                        my ($code, $data) = @{$subfield};
675
                        my @mappings;
676
                        push @mappings, @{ $subfields_mappings->{$code} } if $subfields_mappings->{$code};
677
                        if (@mappings) {
678
                            $self->_process_mappings(\@mappings, $data, $record_document, {
679
                                    data_source => 'subfield',
680
                                    code => $code,
681
                                    field => $field
682
                                }
683
                            );
684
                        }
685
                    }
686
                }
687
            }
688
        }
689
667
        if (C4::Context->preference('IncludeSeeFromInSearches') and $self->index eq 'biblios') {
690
        if (C4::Context->preference('IncludeSeeFromInSearches') and $self->index eq 'biblios') {
668
            foreach my $field (Koha::Filter::MARC::EmbedSeeFromHeadings->new->fields($record)) {
691
            foreach my $field (Koha::Filter::MARC::EmbedSeeFromHeadings->new->fields($record)) {
669
                my $data_field_rules = $data_fields_rules->{$field->tag()};
692
                my $data_field_rules = $data_fields_rules->{$field->tag()};
(-)a/misc/migration_tools/rebuild_zebra.pl (-1 / +1 lines)
Lines 661-666 sub get_corrected_marc_record { Link Here
661
661
662
            my @filters;
662
            my @filters;
663
            push @filters, 'EmbedItemsAvailability';
663
            push @filters, 'EmbedItemsAvailability';
664
            push @filters, 'EmbedRecordSource';
664
            push @filters, 'EmbedSeeFromHeadings'
665
            push @filters, 'EmbedSeeFromHeadings'
665
                if C4::Context->preference('IncludeSeeFromInSearches');
666
                if C4::Context->preference('IncludeSeeFromInSearches');
666
667
667
- 

Return to bug 36884