Bugzilla – Attachment 113650 Details for
Bug 11175
Show the parent record's component parts in the detailed views
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 11175: Limit the amount of component parts returned
Bug-11175-Limit-the-amount-of-component-parts-retu.patch (text/plain), 9.84 KB, created by
Joonas Kylmälä
on 2020-11-16 08:43:38 UTC
(
hide
)
Description:
Bug 11175: Limit the amount of component parts returned
Filename:
MIME Type:
Creator:
Joonas Kylmälä
Created:
2020-11-16 08:43:38 UTC
Size:
9.84 KB
patch
obsolete
>From 321b318be82ec3f1693f14d1883d42dcaf82fb93 Mon Sep 17 00:00:00 2001 >From: =?UTF-8?q?Joonas=20Kylm=C3=A4l=C3=A4?= <joonas.kylmala@helsinki.fi> >Date: Fri, 13 Nov 2020 19:52:18 +0200 >Subject: [PATCH] Bug 11175: Limit the amount of component parts returned > >There was already before this a limit of 100 results when using >Elasticsearch but then the list of component parts was truncated >silently. This change now limits the amount to hard coded limit of 300 >which is still fast to render. Also when the 300 component part record >limit is reached there is a link in the list now to list all the >records via the cataloging search. > >To test: > 1) Create 300+ component part records and see if the link to list > all the component part records shows up > 2) Make sure prove t/Koha/Util/Search.t passes >--- > C4/XSLT.pm | 21 +++++--- > Koha/Biblio.pm | 26 +++------- > Koha/Util/Search.pm | 57 ++++++++++++++++++++++ > .../intranet-tmpl/prog/en/xslt/MARC21slimUtils.xsl | 6 +++ > t/Koha/Util/Search.t | 42 ++++++++++++++++ > 5 files changed, 125 insertions(+), 27 deletions(-) > create mode 100644 Koha/Util/Search.pm > create mode 100755 t/Koha/Util/Search.t > >diff --git a/C4/XSLT.pm b/C4/XSLT.pm >index bc4a59e528..c8c630a569 100644 >--- a/C4/XSLT.pm >+++ b/C4/XSLT.pm >@@ -31,6 +31,7 @@ use C4::Circulation; > use C4::Reserves; > use Koha::AuthorisedValues; > use Koha::ItemTypes; >+use Koha::Util::Search; > use Koha::XSLT::Base; > use Koha::Libraries; > >@@ -266,11 +267,6 @@ sub XSLTParse4Display { > $variables->{OpenURLResolverURL} = $biblio->get_openurl; > } > } >- my $varxml = "<variables>\n"; >- while (my ($key, $value) = each %$variables) { >- $varxml .= "<variable name=\"$key\">$value</variable>\n"; >- } >- $varxml .= "</variables>\n"; > > my $partsxml = ''; > # possibly insert component records into Detail views >@@ -280,9 +276,14 @@ sub XSLTParse4Display { > ($showcomp eq 'staff' && $xslsyspref !~ m/OPAC/ ) || > ($showcomp eq 'opac' && $xslsyspref =~ m/OPAC/ ) ) { > my $biblio = Koha::Biblios->find( $biblionumber ); >- if ( $biblio->components() ) { >+ my $max_results = 300; >+ >+ if ( $biblio->components($max_results) ) { >+ my $search_query = Koha::Util::Search::get_component_part_query($biblionumber); >+ $variables->{ComponentPartQuery} = $search_query; >+ > my @componentPartRecordXML = ('<componentPartRecords>'); >- for my $cb ( @{ $biblio->components() } ) { >+ for my $cb ( @{ $biblio->components($max_results) } ) { > if( ref $cb eq 'MARC::Record'){ > $cb = $cb->as_xml_record(); > } else { >@@ -298,6 +299,12 @@ sub XSLTParse4Display { > } > } > >+ my $varxml = "<variables>\n"; >+ while (my ($key, $value) = each %$variables) { >+ $varxml .= "<variable name=\"$key\">$value</variable>\n"; >+ } >+ $varxml .= "</variables>\n"; >+ > $xmlrecord =~ s/\<\/record\>/$itemsxml$sysxml$varxml$partsxml\<\/record\>/; > if ($fixamps) { # We need to correct the ampersand entities that Zebra outputs > $xmlrecord =~ s/\&amp;/\&/g; >diff --git a/Koha/Biblio.pm b/Koha/Biblio.pm >index 1f002299ac..f9ae290a92 100644 >--- a/Koha/Biblio.pm >+++ b/Koha/Biblio.pm >@@ -45,6 +45,7 @@ use Koha::Suggestions; > use Koha::Subscriptions; > use Koha::SearchEngine; > use Koha::SearchEngine::Search; >+use Koha::Util::Search; > > =head1 NAME > >@@ -506,31 +507,16 @@ this object (MARC21 773$w points to this) > =cut > > sub components { >- my ($self) = @_; >+ my ($self, $max_results) = @_; > > return if (C4::Context->preference('marcflavour') ne 'MARC21'); > >- my $marc = C4::Biblio::GetMarcBiblio({ biblionumber => $self->id }); >- my $pf001 = $marc->field('001') || undef; >- my $searcher = Koha::SearchEngine::Search->new({index => $Koha::SearchEngine::BIBLIOS_INDEX}); >- >- if (defined($pf001)) { >- my $pf003 = $marc->field('003') || undef; >- my $searchstr; >- >- if (!defined($pf003)) { >- # search for 773$w='Host001' >- $searchstr = "rcn='".$pf001->data()."'"; >- } else { >- # search for (773$w='Host001' and 003='Host003') or 773$w='Host003 Host001') >- $searchstr = "(rcn='".$pf001->data()."' AND cni='".$pf003->data()."')"; >- $searchstr .= " OR rcn='".$pf003->data()." ".$pf001->data()."'"; >- } >+ my $searchstr = Koha::Util::Search::get_component_part_query($self->id); > >- my ( $errors, $results, $total_hits ) = $searcher->simple_search_compat( $searchstr, 0, undef ); >+ if (defined($searchstr)) { >+ my $searcher = Koha::SearchEngine::Search->new({index => $Koha::SearchEngine::BIBLIOS_INDEX}); >+ my ( $errors, $results, $total_hits ) = $searcher->simple_search_compat( $searchstr, 0, $max_results ); > $self->{_components} = $results if ( defined($results) && scalar(@$results) ); >- } else { >- warn "Record $self->id has no 001"; > } > > return $self->{_components} || (); >diff --git a/Koha/Util/Search.pm b/Koha/Util/Search.pm >new file mode 100644 >index 0000000000..4e1c9706a8 >--- /dev/null >+++ b/Koha/Util/Search.pm >@@ -0,0 +1,57 @@ >+package Koha::Util::Search; >+ >+# Copyright 2020 University of Helsinki >+# >+# 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>. >+ >+use Modern::Perl; >+ >+use C4::Biblio; >+ >+=head1 NAME >+ >+Koha::Util::Search â functions to build complex search queries >+ >+=head1 FUNCTIONS >+ >+=head2 get_component_part_query >+ >+Returns a query which can be used to search for all component parts of MARC21 biblios >+ >+=cut >+ >+sub get_component_part_query { >+ my ($biblionumber) = @_; >+ >+ my $marc = C4::Biblio::GetMarcBiblio({ biblionumber => $biblionumber }); >+ my $pf001 = $marc->field('001') || undef; >+ >+ if (defined($pf001)) { >+ my $pf003 = $marc->field('003') || undef; >+ my $searchstr; >+ >+ if (!defined($pf003)) { >+ # search for 773$w='Host001' >+ $searchstr = "rcn='".$pf001->data()."'"; >+ } else { >+ # search for (773$w='Host001' and 003='Host003') or 773$w='Host003 Host001') >+ $searchstr = "(rcn='".$pf001->data()."' AND cni='".$pf003->data()."')"; >+ $searchstr .= " OR rcn='".$pf003->data()." ".$pf001->data()."'"; >+ } >+ } >+} >+ >+1; >diff --git a/koha-tmpl/intranet-tmpl/prog/en/xslt/MARC21slimUtils.xsl b/koha-tmpl/intranet-tmpl/prog/en/xslt/MARC21slimUtils.xsl >index 13e5887fec..42fe45052e 100644 >--- a/koha-tmpl/intranet-tmpl/prog/en/xslt/MARC21slimUtils.xsl >+++ b/koha-tmpl/intranet-tmpl/prog/en/xslt/MARC21slimUtils.xsl >@@ -581,6 +581,7 @@ > <xsl:template name="showComponentParts"> > <!-- Component part records: Displaying title and author of component part records --> > <xsl:if test="marc:componentPartRecords"> >+ <xsl:variable name="ComponentPartQuery" select="marc:variables/marc:variable[@name='ComponentPartQuery']" /> > <div class="results_summary componentPartRecordsContainer"> > <h5>Component part records</h5> > <ol class="componentParts"> >@@ -640,6 +641,11 @@ > </li> > </xsl:for-each> > </ol> >+ <xsl:choose> >+ <xsl:when test="count(marc:componentPartRecords/marc:record) = 300"> >+ <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> >+ </xsl:when> >+ </xsl:choose> > </div> > </xsl:if> > </xsl:template> >diff --git a/t/Koha/Util/Search.t b/t/Koha/Util/Search.t >new file mode 100755 >index 0000000000..c56b9404e2 >--- /dev/null >+++ b/t/Koha/Util/Search.t >@@ -0,0 +1,42 @@ >+#!/usr/bin/perl >+# >+# Copyright 2020 University of Helsinki >+# >+# 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>. >+ >+use Modern::Perl; >+ >+use Test::More tests => 1; >+use t::lib::TestBuilder; >+ >+use C4::Biblio; >+use Koha::Util::Search; >+use MARC::Field; >+ >+my $builder = t::lib::TestBuilder->new; >+ >+subtest 'get_component_part_query' => sub { >+ plan tests => 1; >+ >+ my $biblio = $builder->build_sample_biblio(); >+ my $biblionumber = $biblio->biblionumber; >+ my $record = GetMarcBiblio({ biblionumber => $biblionumber }); >+ my $marc_001_field = MARC::Field->new('001', $biblionumber); >+ $record->append_fields($marc_001_field); >+ ModBiblioMarc($record, $biblionumber); >+ >+ is(Koha::Util::Search::get_component_part_query($biblionumber), "rcn='$biblionumber'"); >+}; >-- >2.11.0
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 11175
:
22612
|
22649
|
23049
|
24788
|
24789
|
24790
|
24791
|
26402
|
26403
|
26404
|
26405
|
26766
|
26767
|
78022
|
78023
|
78024
|
79687
|
79803
|
79809
|
79810
|
105631
|
105641
|
105703
|
105706
|
105707
|
106692
|
112838
|
112839
|
112840
|
112841
|
112846
|
112847
|
112851
|
112852
|
112853
|
112854
|
112855
|
112856
|
112857
|
113649
|
113650
|
113962
|
113964
|
114326
|
114327
|
114328
|
114329
|
114330
|
114331
|
114332
|
114333
|
114334
|
116819
|
116820
|
116821
|
116822
|
116823
|
116824
|
116825
|
116826
|
116827
|
116828
|
119499
|
119506
|
120206
|
122707
|
122708
|
122709
|
122710
|
122711
|
122712
|
122713
|
122714
|
122715
|
122716
|
122717
|
122718
|
123081
|
123082
|
123083
|
123084
|
123085
|
123086
|
123087
|
123088
|
123089
|
123090
|
123091
|
123092
|
123093
|
123406
|
123410
|
123508
|
123509
|
123510
|
123511
|
123512
|
123513
|
123514
|
123515
|
123516
|
123517
|
123518
|
123519
|
123520
|
123521
|
123522
|
123523
|
123524
|
123541
|
123542
|
123543
|
123544
|
123545
|
123546
|
123547
|
123548
|
123549
|
123550
|
123551
|
123552
|
123553
|
123554
|
123555
|
123556
|
123557
|
123562
|
123564
|
123569
|
123570
|
123571
|
123572
|
123573
|
123574
|
123582
|
123583
|
123608
|
123609
|
123611
|
123612
|
123613
|
123614
|
123617
|
123618
|
123619
|
123620
|
123621
|
123622
|
123623
|
123624
|
123625
|
123626
|
123627
|
123628
|
123629
|
123630
|
123631
|
123632
|
123633
|
123634
|
123635
|
123636
|
123637
|
123638
|
123736
|
123737
|
123738
|
123739
|
123740
|
123741
|
123742
|
123743
|
123744
|
123745
|
123746
|
123747
|
123748
|
123749
|
123750
|
123751
|
123752
|
123753
|
123754
|
123755
|
123756
|
124134
|
124135
|
124136
|
124137
|
124138
|
124139
|
124140
|
124141
|
124142
|
124143
|
124144
|
124145
|
124146
|
124147
|
124148
|
124149
|
124150
|
124151
|
124152
|
124153
|
124154
|
124155
|
124382
|
124383
|
124384
|
124385
|
124386
|
124387
|
124388
|
124389
|
124390
|
124391
|
124392
|
124393
|
124394
|
124395
|
124396
|
124397
|
124398
|
124399
|
124400
|
124401
|
124402
|
124403
|
124404
|
124534
|
124535
|
124536
|
124537
|
124538
|
124539
|
124540
|
124541
|
124542
|
124544
|
124545
|
124546
|
124547
|
124548
|
124549
|
124550
|
124551
|
124552
|
124553
|
124554
|
124555
|
124556
|
124557
|
126057
|
126058
|
126059
|
126060
|
126061
|
126062
|
126063
|
126064
|
126065
|
126066
|
126067
|
126068
|
126069
|
126070
|
126071
|
126072
|
126073
|
126074
|
126075
|
126076
|
126077
|
126078
|
126079
|
126080
|
126081
|
126084
|
126441
|
126442
|
126443
|
126687
|
126688
|
126689
|
126690
|
126692
|
126693
|
126694
|
126695
|
126696
|
126697
|
126698
|
126699
|
126700
|
126701
|
126702
|
126703
|
126704
|
126705
|
126706
|
126707
|
126708
|
126709
|
126710
|
126711
|
126712
|
126713
|
126714
|
126715
|
126716
|
126717
|
126718
|
126719
|
126720
|
126721
|
126722
|
126723
|
126724
|
126725
|
126726
|
126727
|
126728
|
126729
|
126730
|
126731
|
126732
|
126733
|
126734
|
126735
|
126736
|
126737
|
126738
|
126739
|
126740
|
126741
|
126742
|
126743
|
126744
|
126745
|
126816
|
126817
|
126869
|
126870
|
126871
|
126872
|
126873
|
126874
|
126875
|
126876
|
126877
|
126878
|
126879
|
126880
|
126881
|
126882
|
126883
|
126884
|
126885
|
126886
|
126887
|
126888
|
126889
|
126890
|
126891
|
126892
|
126893
|
126894
|
126895
|
126897
|
126898
|
126904
|
126911
|
126912
|
126913