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

(-)a/C4/XSLT.pm (-7 / +14 lines)
Lines 28-33 use C4::Koha qw( xml_escape ); Link Here
28
use C4::Biblio qw( GetAuthorisedValueDesc GetFrameworkCode GetMarcStructure );
28
use C4::Biblio qw( GetAuthorisedValueDesc GetFrameworkCode GetMarcStructure );
29
use Koha::AuthorisedValues;
29
use Koha::AuthorisedValues;
30
use Koha::ItemTypes;
30
use Koha::ItemTypes;
31
use Koha::Util::Search;
31
use Koha::XSLT::Base;
32
use Koha::XSLT::Base;
32
use Koha::Libraries;
33
use Koha::Libraries;
33
34
Lines 265-275 sub XSLTParse4Display { Link Here
265
            $variables->{OpenURLResolverURL} = $biblio->get_openurl;
266
            $variables->{OpenURLResolverURL} = $biblio->get_openurl;
266
        }
267
        }
267
    }
268
    }
268
    my $varxml = "<variables>\n";
269
    while (my ($key, $value) = each %$variables) {
270
        $varxml .= "<variable name=\"$key\">$value</variable>\n";
271
    }
272
    $varxml .= "</variables>\n";
273
269
274
    my $partsxml = '';
270
    my $partsxml = '';
275
    # possibly insert component records into Detail views
271
    # possibly insert component records into Detail views
Lines 279-287 sub XSLTParse4Display { Link Here
279
             ($showcomp eq 'staff' && $xslsyspref !~ m/OPAC/ ) ||
275
             ($showcomp eq 'staff' && $xslsyspref !~ m/OPAC/ ) ||
280
             ($showcomp eq 'opac' && $xslsyspref =~ m/OPAC/  ) ) {
276
             ($showcomp eq 'opac' && $xslsyspref =~ m/OPAC/  ) ) {
281
            my $biblio = Koha::Biblios->find( $biblionumber );
277
            my $biblio = Koha::Biblios->find( $biblionumber );
282
            if ( $biblio->components() ) {
278
            my $max_results = 300;
279
280
            if ( $biblio->components($max_results) ) {
281
                my $search_query = Koha::Util::Search::get_component_part_query($biblionumber);
282
                $variables->{ComponentPartQuery} = $search_query;
283
283
                my @componentPartRecordXML = ('<componentPartRecords>');
284
                my @componentPartRecordXML = ('<componentPartRecords>');
284
                for my $cb ( @{ $biblio->components() } ) {
285
                for my $cb ( @{ $biblio->components($max_results) } ) {
285
                    if( ref $cb eq 'MARC::Record'){
286
                    if( ref $cb eq 'MARC::Record'){
286
                        $cb = $cb->as_xml_record();
287
                        $cb = $cb->as_xml_record();
287
                    } else {
288
                    } else {
Lines 297-302 sub XSLTParse4Display { Link Here
297
        }
298
        }
298
    }
299
    }
299
300
301
    my $varxml = "<variables>\n";
302
    while (my ($key, $value) = each %$variables) {
303
        $varxml .= "<variable name=\"$key\">$value</variable>\n";
304
    }
305
    $varxml .= "</variables>\n";
306
300
    $xmlrecord =~ s/\<\/record\>/$itemsxml$sysxml$varxml$partsxml\<\/record\>/;
307
    $xmlrecord =~ s/\<\/record\>/$itemsxml$sysxml$varxml$partsxml\<\/record\>/;
301
    if ($fixamps) { # We need to correct the ampersand entities that Zebra outputs
308
    if ($fixamps) { # We need to correct the ampersand entities that Zebra outputs
302
        $xmlrecord =~ s/\&amp;amp;/\&amp;/g;
309
        $xmlrecord =~ s/\&amp;amp;/\&amp;/g;
(-)a/Koha/Biblio.pm (-20 / +6 lines)
Lines 43-48 use Koha::Suggestions; Link Here
43
use Koha::Subscriptions;
43
use Koha::Subscriptions;
44
use Koha::SearchEngine;
44
use Koha::SearchEngine;
45
use Koha::SearchEngine::Search;
45
use Koha::SearchEngine::Search;
46
use Koha::Util::Search;
46
47
47
=head1 NAME
48
=head1 NAME
48
49
Lines 507-537 this object (MARC21 773$w points to this) Link Here
507
=cut
508
=cut
508
509
509
sub components {
510
sub components {
510
    my ($self) = @_;
511
    my ($self, $max_results) = @_;
511
512
512
    return if (C4::Context->preference('marcflavour') ne 'MARC21');
513
    return if (C4::Context->preference('marcflavour') ne 'MARC21');
513
514
514
    my $marc = C4::Biblio::GetMarcBiblio({ biblionumber => $self->id });
515
    my $searchstr = Koha::Util::Search::get_component_part_query($self->id);
515
    my $pf001 = $marc->field('001') || undef;
516
    my $searcher = Koha::SearchEngine::Search->new({index => $Koha::SearchEngine::BIBLIOS_INDEX});
517
518
    if (defined($pf001)) {
519
        my $pf003 = $marc->field('003') || undef;
520
        my $searchstr;
521
522
        if (!defined($pf003)) {
523
            # search for 773$w='Host001'
524
            $searchstr = "rcn='".$pf001->data()."'";
525
        } else {
526
            # search for (773$w='Host001' and 003='Host003') or 773$w='Host003 Host001')
527
            $searchstr = "(rcn='".$pf001->data()."' AND cni='".$pf003->data()."')";
528
            $searchstr .= " OR rcn='".$pf003->data()." ".$pf001->data()."'";
529
        }
530
516
531
        my ( $errors, $results, $total_hits ) = $searcher->simple_search_compat( $searchstr, 0, undef );
517
    if (defined($searchstr)) {
518
        my $searcher = Koha::SearchEngine::Search->new({index => $Koha::SearchEngine::BIBLIOS_INDEX});
519
        my ( $errors, $results, $total_hits ) = $searcher->simple_search_compat( $searchstr, 0, $max_results );
532
        $self->{_components} = $results if ( defined($results) && scalar(@$results) );
520
        $self->{_components} = $results if ( defined($results) && scalar(@$results) );
533
    } else {
534
        warn "Record $self->id has no 001";
535
    }
521
    }
536
522
537
    return $self->{_components} || ();
523
    return $self->{_components} || ();
(-)a/Koha/Util/Search.pm (+57 lines)
Line 0 Link Here
1
package Koha::Util::Search;
2
3
# Copyright 2020 University of Helsinki
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
use Modern::Perl;
21
22
use C4::Biblio;
23
24
=head1 NAME
25
26
Koha::Util::Search – functions to build complex search queries
27
28
=head1 FUNCTIONS
29
30
=head2 get_component_part_query
31
32
Returns a query which can be used to search for all component parts of MARC21 biblios
33
34
=cut
35
36
sub get_component_part_query {
37
    my ($biblionumber) = @_;
38
39
    my $marc = C4::Biblio::GetMarcBiblio({ biblionumber => $biblionumber });
40
    my $pf001 = $marc->field('001') || undef;
41
42
    if (defined($pf001)) {
43
        my $pf003 = $marc->field('003') || undef;
44
        my $searchstr;
45
46
        if (!defined($pf003)) {
47
            # search for 773$w='Host001'
48
            $searchstr = "rcn='".$pf001->data()."'";
49
        } else {
50
            # search for (773$w='Host001' and 003='Host003') or 773$w='Host003 Host001')
51
            $searchstr = "(rcn='".$pf001->data()."' AND cni='".$pf003->data()."')";
52
            $searchstr .= " OR rcn='".$pf003->data()." ".$pf001->data()."'";
53
        }
54
    }
55
}
56
57
1;
(-)a/koha-tmpl/intranet-tmpl/prog/en/xslt/MARC21slimUtils.xsl (+6 lines)
Lines 581-586 Link Here
581
    <xsl:template name="showComponentParts">
581
    <xsl:template name="showComponentParts">
582
        <!-- Component part records: Displaying title and author of component part records -->
582
        <!-- Component part records: Displaying title and author of component part records -->
583
        <xsl:if test="marc:componentPartRecords">
583
        <xsl:if test="marc:componentPartRecords">
584
            <xsl:variable name="ComponentPartQuery" select="marc:variables/marc:variable[@name='ComponentPartQuery']" />
584
            <div class="results_summary componentPartRecordsContainer">
585
            <div class="results_summary componentPartRecordsContainer">
585
                <h5>Component part records</h5>
586
                <h5>Component part records</h5>
586
                <ol class="componentParts">
587
                <ol class="componentParts">
Lines 640-645 Link Here
640
                        </li>
641
                        </li>
641
                    </xsl:for-each>
642
                    </xsl:for-each>
642
                </ol>
643
                </ol>
644
                <xsl:choose>
645
                    <xsl:when test="count(marc:componentPartRecords/marc:record) = 300">
646
                        <p>Only 300 results are shown: <a><xsl:attribute name="href">/cgi-bin/koha/catalogue/search.pl?q=<xsl:value-of select="str:encode-uri($ComponentPartQuery, true())"/></xsl:attribute>show all component parts</a></p>
647
                     </xsl:when>
648
                </xsl:choose>
643
            </div>
649
            </div>
644
        </xsl:if>
650
        </xsl:if>
645
    </xsl:template>
651
    </xsl:template>
(-)a/t/Koha/Util/Search.t (-1 / +42 lines)
Line 0 Link Here
0
- 
1
#!/usr/bin/perl
2
#
3
# Copyright 2020 University of Helsinki
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
use Modern::Perl;
21
22
use Test::More tests => 1;
23
use t::lib::TestBuilder;
24
25
use C4::Biblio;
26
use Koha::Util::Search;
27
use MARC::Field;
28
29
my $builder = t::lib::TestBuilder->new;
30
31
subtest 'get_component_part_query' => sub {
32
    plan tests => 1;
33
34
    my $biblio = $builder->build_sample_biblio();
35
    my $biblionumber = $biblio->biblionumber;
36
    my $record = GetMarcBiblio({ biblionumber => $biblionumber });
37
    my $marc_001_field = MARC::Field->new('001', $biblionumber);
38
    $record->append_fields($marc_001_field);
39
    ModBiblioMarc($record, $biblionumber);
40
41
    is(Koha::Util::Search::get_component_part_query($biblionumber), "rcn='$biblionumber'");
42
};

Return to bug 11175