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

(-)a/C4/XSLT.pm (-7 / +14 lines)
Lines 31-36 use C4::Circulation; Link Here
31
use C4::Reserves;
31
use C4::Reserves;
32
use Koha::AuthorisedValues;
32
use Koha::AuthorisedValues;
33
use Koha::ItemTypes;
33
use Koha::ItemTypes;
34
use Koha::Util::Search;
34
use Koha::XSLT::Base;
35
use Koha::XSLT::Base;
35
use Koha::Libraries;
36
use Koha::Libraries;
36
37
Lines 266-276 sub XSLTParse4Display { Link Here
266
            $variables->{OpenURLResolverURL} = $biblio->get_openurl;
267
            $variables->{OpenURLResolverURL} = $biblio->get_openurl;
267
        }
268
        }
268
    }
269
    }
269
    my $varxml = "<variables>\n";
270
    while (my ($key, $value) = each %$variables) {
271
        $varxml .= "<variable name=\"$key\">$value</variable>\n";
272
    }
273
    $varxml .= "</variables>\n";
274
270
275
    my $partsxml = '';
271
    my $partsxml = '';
276
    # possibly insert component records into Detail views
272
    # possibly insert component records into Detail views
Lines 280-288 sub XSLTParse4Display { Link Here
280
             ($showcomp eq 'staff' && $xslsyspref !~ m/OPAC/ ) ||
276
             ($showcomp eq 'staff' && $xslsyspref !~ m/OPAC/ ) ||
281
             ($showcomp eq 'opac' && $xslsyspref =~ m/OPAC/  ) ) {
277
             ($showcomp eq 'opac' && $xslsyspref =~ m/OPAC/  ) ) {
282
            my $biblio = Koha::Biblios->find( $biblionumber );
278
            my $biblio = Koha::Biblios->find( $biblionumber );
283
            if ( $biblio->components() ) {
279
            my $max_results = 300;
280
281
            if ( $biblio->components($max_results) ) {
282
                my $search_query = Koha::Util::Search::get_component_part_query($biblionumber);
283
                $variables->{ComponentPartQuery} = $search_query;
284
284
                my @componentPartRecordXML = ('<componentPartRecords>');
285
                my @componentPartRecordXML = ('<componentPartRecords>');
285
                for my $cb ( @{ $biblio->components() } ) {
286
                for my $cb ( @{ $biblio->components($max_results) } ) {
286
                    if( ref $cb eq 'MARC::Record'){
287
                    if( ref $cb eq 'MARC::Record'){
287
                        $cb = $cb->as_xml_record();
288
                        $cb = $cb->as_xml_record();
288
                    } else {
289
                    } else {
Lines 298-303 sub XSLTParse4Display { Link Here
298
        }
299
        }
299
    }
300
    }
300
301
302
    my $varxml = "<variables>\n";
303
    while (my ($key, $value) = each %$variables) {
304
        $varxml .= "<variable name=\"$key\">$value</variable>\n";
305
    }
306
    $varxml .= "</variables>\n";
307
301
    $xmlrecord =~ s/\<\/record\>/$itemsxml$sysxml$varxml$partsxml\<\/record\>/;
308
    $xmlrecord =~ s/\<\/record\>/$itemsxml$sysxml$varxml$partsxml\<\/record\>/;
302
    if ($fixamps) { # We need to correct the ampersand entities that Zebra outputs
309
    if ($fixamps) { # We need to correct the ampersand entities that Zebra outputs
303
        $xmlrecord =~ s/\&amp;amp;/\&amp;/g;
310
        $xmlrecord =~ s/\&amp;amp;/\&amp;/g;
(-)a/Koha/Biblio.pm (-20 / +6 lines)
Lines 45-50 use Koha::Suggestions; Link Here
45
use Koha::Subscriptions;
45
use Koha::Subscriptions;
46
use Koha::SearchEngine;
46
use Koha::SearchEngine;
47
use Koha::SearchEngine::Search;
47
use Koha::SearchEngine::Search;
48
use Koha::Util::Search;
48
49
49
=head1 NAME
50
=head1 NAME
50
51
Lines 509-539 this object (MARC21 773$w points to this) Link Here
509
=cut
510
=cut
510
511
511
sub components {
512
sub components {
512
    my ($self) = @_;
513
    my ($self, $max_results) = @_;
513
514
514
    return if (C4::Context->preference('marcflavour') ne 'MARC21');
515
    return if (C4::Context->preference('marcflavour') ne 'MARC21');
515
516
516
    my $marc = C4::Biblio::GetMarcBiblio({ biblionumber => $self->id });
517
    my $searchstr = Koha::Util::Search::get_component_part_query($self->id);
517
    my $pf001 = $marc->field('001') || undef;
518
    my $searcher = Koha::SearchEngine::Search->new({index => $Koha::SearchEngine::BIBLIOS_INDEX});
519
520
    if (defined($pf001)) {
521
        my $pf003 = $marc->field('003') || undef;
522
        my $searchstr;
523
524
        if (!defined($pf003)) {
525
            # search for 773$w='Host001'
526
            $searchstr = "rcn='".$pf001->data()."'";
527
        } else {
528
            # search for (773$w='Host001' and 003='Host003') or 773$w='Host003 Host001')
529
            $searchstr = "(rcn='".$pf001->data()."' AND cni='".$pf003->data()."')";
530
            $searchstr .= " OR rcn='".$pf003->data()." ".$pf001->data()."'";
531
        }
532
518
533
        my ( $errors, $results, $total_hits ) = $searcher->simple_search_compat( $searchstr, 0, undef );
519
    if (defined($searchstr)) {
520
        my $searcher = Koha::SearchEngine::Search->new({index => $Koha::SearchEngine::BIBLIOS_INDEX});
521
        my ( $errors, $results, $total_hits ) = $searcher->simple_search_compat( $searchstr, 0, $max_results );
534
        $self->{_components} = $results if ( defined($results) && scalar(@$results) );
522
        $self->{_components} = $results if ( defined($results) && scalar(@$results) );
535
    } else {
536
        warn "Record $self->id has no 001";
537
    }
523
    }
538
524
539
    return $self->{_components} || ();
525
    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