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 279-289 sub XSLTParse4Display { Link Here
279
            $variables->{OpenURLResolverURL} = $biblio->get_openurl;
280
            $variables->{OpenURLResolverURL} = $biblio->get_openurl;
280
        }
281
        }
281
    }
282
    }
282
    my $varxml = "<variables>\n";
283
    while (my ($key, $value) = each %$variables) {
284
        $varxml .= "<variable name=\"$key\">$value</variable>\n";
285
    }
286
    $varxml .= "</variables>\n";
287
283
288
    my $partsxml = '';
284
    my $partsxml = '';
289
    # possibly insert component records into Detail views
285
    # possibly insert component records into Detail views
Lines 293-301 sub XSLTParse4Display { Link Here
293
             ($showcomp eq 'staff' && $xslsyspref !~ m/OPAC/ ) ||
289
             ($showcomp eq 'staff' && $xslsyspref !~ m/OPAC/ ) ||
294
             ($showcomp eq 'opac' && $xslsyspref =~ m/OPAC/  ) ) {
290
             ($showcomp eq 'opac' && $xslsyspref =~ m/OPAC/  ) ) {
295
            my $biblio = Koha::Biblios->find( $biblionumber );
291
            my $biblio = Koha::Biblios->find( $biblionumber );
296
            if ( $biblio->components() ) {
292
            my $max_results = 300;
293
294
            if ( $biblio->components($max_results) ) {
295
                my $search_query = Koha::Util::Search::get_component_part_query($biblionumber);
296
                $variables->{ComponentPartQuery} = $search_query;
297
297
                my @componentPartRecordXML = ('<componentPartRecords>');
298
                my @componentPartRecordXML = ('<componentPartRecords>');
298
                for my $cb ( @{ $biblio->components() } ) {
299
                for my $cb ( @{ $biblio->components($max_results) } ) {
299
                    if( ref $cb eq 'MARC::Record'){
300
                    if( ref $cb eq 'MARC::Record'){
300
                        $cb = $cb->as_xml_record();
301
                        $cb = $cb->as_xml_record();
301
                    } else {
302
                    } else {
Lines 311-316 sub XSLTParse4Display { Link Here
311
        }
312
        }
312
    }
313
    }
313
314
315
    my $varxml = "<variables>\n";
316
    while (my ($key, $value) = each %$variables) {
317
        $varxml .= "<variable name=\"$key\">$value</variable>\n";
318
    }
319
    $varxml .= "</variables>\n";
320
314
    my $sysxml = get_xslt_sysprefs();
321
    my $sysxml = get_xslt_sysprefs();
315
    $xmlrecord =~ s/\<\/record\>/$itemsxml$sysxml$varxml$partsxml\<\/record\>/;
322
    $xmlrecord =~ s/\<\/record\>/$itemsxml$sysxml$varxml$partsxml\<\/record\>/;
316
    if ($fixamps) { # We need to correct the ampersand entities that Zebra outputs
323
    if ($fixamps) { # We need to correct the ampersand entities that Zebra outputs
(-)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 488-518 this object (MARC21 773$w points to this) Link Here
488
=cut
489
=cut
489
490
490
sub components {
491
sub components {
491
    my ($self) = @_;
492
    my ($self, $max_results) = @_;
492
493
493
    return if (C4::Context->preference('marcflavour') ne 'MARC21');
494
    return if (C4::Context->preference('marcflavour') ne 'MARC21');
494
495
495
    my $marc = C4::Biblio::GetMarcBiblio({ biblionumber => $self->id });
496
    my $searchstr = Koha::Util::Search::get_component_part_query($self->id);
496
    my $pf001 = $marc->field('001') || undef;
497
    my $searcher = Koha::SearchEngine::Search->new({index => $Koha::SearchEngine::BIBLIOS_INDEX});
498
499
    if (defined($pf001)) {
500
        my $pf003 = $marc->field('003') || undef;
501
        my $searchstr;
502
503
        if (!defined($pf003)) {
504
            # search for 773$w='Host001'
505
            $searchstr = "rcn='".$pf001->data()."'";
506
        } else {
507
            # search for (773$w='Host001' and 003='Host003') or 773$w='Host003 Host001')
508
            $searchstr = "(rcn='".$pf001->data()."' AND cni='".$pf003->data()."')";
509
            $searchstr .= " OR rcn='".$pf003->data()." ".$pf001->data()."'";
510
        }
511
497
512
        my ( $errors, $results, $total_hits ) = $searcher->simple_search_compat( $searchstr, 0, undef );
498
    if (defined($searchstr)) {
499
        my $searcher = Koha::SearchEngine::Search->new({index => $Koha::SearchEngine::BIBLIOS_INDEX});
500
        my ( $errors, $results, $total_hits ) = $searcher->simple_search_compat( $searchstr, 0, $max_results );
513
        $self->{_components} = $results if ( defined($results) && scalar(@$results) );
501
        $self->{_components} = $results if ( defined($results) && scalar(@$results) );
514
    } else {
515
        warn "Record $self->id has no 001";
516
    }
502
    }
517
503
518
    return $self->{_components} || ();
504
    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