Bugzilla – Attachment 122035 Details for
Bug 27138
Host items are not included in Z39 results when using EasyAnalytics
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 27138: Add preference EmbedHostItemsInSearchEngine
Bug-27138-Add-preference-EmbedHostItemsInSearchEng.patch (text/plain), 9.50 KB, created by
Nick Clemens (kidclamp)
on 2021-06-16 11:57:50 UTC
(
hide
)
Description:
Bug 27138: Add preference EmbedHostItemsInSearchEngine
Filename:
MIME Type:
Creator:
Nick Clemens (kidclamp)
Created:
2021-06-16 11:57:50 UTC
Size:
9.50 KB
patch
obsolete
>From 79b20181c2567b7f8e47ac0375b4702372b95907 Mon Sep 17 00:00:00 2001 >From: Nick Clemens <nick@bywatersolutions.com> >Date: Wed, 16 Jun 2021 11:57:31 +0000 >Subject: [PATCH] Bug 27138: Add preference EmbedHostItemsInSearchEngine > >--- > C4/Biblio.pm | 2 +- > C4/Search.pm | 23 ++++++++++++++++++++++ > C4/XSLT.pm | 3 ++- > .../bug_27138_add_embedHostItems_syspref.perl | 9 +++++++++ > installer/data/mysql/mandatory/sysprefs.sql | 1 + > .../en/modules/admin/preferences/searching.pref | 7 +++++++ > misc/migration_tools/rebuild_zebra.pl | 3 ++- > t/db_dependent/Items.t | 19 ++++++++++++++++-- > 8 files changed, 62 insertions(+), 5 deletions(-) > create mode 100644 installer/data/mysql/atomicupdate/bug_27138_add_embedHostItems_syspref.perl > >diff --git a/C4/Biblio.pm b/C4/Biblio.pm >index 3964be6df9..dcf7b3fe2b 100644 >--- a/C4/Biblio.pm >+++ b/C4/Biblio.pm >@@ -1171,7 +1171,7 @@ sub GetMarcBiblio { > > my $biblionumber = $params->{biblionumber}; > my $embeditems = $params->{embed_items} || 0; >- my $embedhostitems = $params->{embed_host_items} // 0; >+ my $embedhostitems = $params->{embed_host_items} && C4::Context->preference('EmbedHostItemsInSearchEngine') // 0; > my $opac = $params->{opac} || 0; > my $borcat = $params->{borcat} // q{}; > >diff --git a/C4/Search.pm b/C4/Search.pm >index 6c876a930c..2275a34878 100644 >--- a/C4/Search.pm >+++ b/C4/Search.pm >@@ -1773,6 +1773,29 @@ sub searchResults { > my @fields = $marcrecord->field($itemtag); > my $marcflavor = C4::Context->preference("marcflavour"); > >+ # adding linked items that belong to host records >+ if ( C4::Context->preference('EasyAnalyticalRecords') && !C4::Context->preference('EmbedHostItemsInSearchEngine') ) { >+ my $analyticsfield = '773'; >+ if ($marcflavor eq 'MARC21' || $marcflavor eq 'NORMARC') { >+ $analyticsfield = '773'; >+ } elsif ($marcflavor eq 'UNIMARC') { >+ $analyticsfield = '461'; >+ } >+ foreach my $hostfield ( $marcrecord->field($analyticsfield)) { >+ my $hostbiblionumber = $hostfield->subfield("0"); >+ my $linkeditemnumber = $hostfield->subfield("9"); >+ if( $hostbiblionumber ) { >+ my $linkeditemmarc = C4::Items::GetMarcItem( $hostbiblionumber, $linkeditemnumber ); >+ if ($linkeditemmarc) { >+ my $linkeditemfield = $linkeditemmarc->field($itemtag); >+ if ($linkeditemfield) { >+ push( @fields, $linkeditemfield ); >+ } >+ } >+ } >+ } >+ } >+ > # Setting item statuses for display > my @available_items_loop; > my @onloan_items_loop; >diff --git a/C4/XSLT.pm b/C4/XSLT.pm >index de053ca692..9dd4e9ec14 100644 >--- a/C4/XSLT.pm >+++ b/C4/XSLT.pm >@@ -297,7 +297,8 @@ Is only used in this module currently. > sub buildKohaItemsNamespace { > my ($biblionumber, $hidden_items) = @_; > >- my @host_itemnumbers = C4::Items::get_hostitemnumbers_of( $biblionumber ); >+ my @host_itemnumbers = (); >+ @host_itemnumbers = C4::Items::get_hostitemnumbers_of( $biblionumber ) if C4::Context->preference('EmbedHostItemsInSearchEngine'); > $hidden_items ||= []; > my @items = Koha::Items->search( > { >diff --git a/installer/data/mysql/atomicupdate/bug_27138_add_embedHostItems_syspref.perl b/installer/data/mysql/atomicupdate/bug_27138_add_embedHostItems_syspref.perl >new file mode 100644 >index 0000000000..831443d937 >--- /dev/null >+++ b/installer/data/mysql/atomicupdate/bug_27138_add_embedHostItems_syspref.perl >@@ -0,0 +1,9 @@ >+$DBversion = 'XXX'; >+if( CheckVersion( $DBversion ) ) { >+ # you can use $dbh here like: >+ $dbh->do(q{ >+ INSERT IGNORE INTO systempreferences ( `variable`, `value`, `options`, `explanation`, `type` ) VALUES >+ ('EmbedHostItemsInSearchEngine','0','','Add host items to records in the search engine','YesNo'); >+ }); >+ NewVersion( $DBversion, 27138, "Add system preference EmbedHostItemsInSearchEngine"); >+} >diff --git a/installer/data/mysql/mandatory/sysprefs.sql b/installer/data/mysql/mandatory/sysprefs.sql >index 0a86168ee0..54b9c2f7cc 100644 >--- a/installer/data/mysql/mandatory/sysprefs.sql >+++ b/installer/data/mysql/mandatory/sysprefs.sql >@@ -191,6 +191,7 @@ INSERT INTO systempreferences ( `variable`, `value`, `options`, `explanation`, ` > ('EmailAddressForSuggestions','','',' If you choose EmailAddressForSuggestions you have to enter a valid email address: ','free'), > ('emailLibrarianWhenHoldIsPlaced','0',NULL,'If ON, emails the librarian whenever a hold is placed','YesNo'), > ('EmailPurchaseSuggestions','0','0|EmailAddressForSuggestions|BranchEmailAddress|KohaAdminEmailAddress','Choose email address that new purchase suggestions will be sent to: ','Choice'), >+('EmbedHostItemsInSearchEngine','0','','Add host items to records in the search engine','YesNo'), > ('EnableAdvancedCatalogingEditor','0','','Enable the Rancor advanced cataloging editor','YesNo'), > ('EnableBorrowerFiles','0',NULL,'If enabled, allows librarians to upload and attach arbitrary files to a borrower record.','YesNo'), > ('EnableOpacSearchHistory','1','YesNo','Enable or disable opac search history',''), >diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/searching.pref b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/searching.pref >index 25b3878307..9c61f8b1fa 100644 >--- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/searching.pref >+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/searching.pref >@@ -87,6 +87,13 @@ Searching: > 0: Disable > - "the cross_fields option for Elasticsearch searches, supported in Elasticsearch 6.X and above." > - "See documentation at https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-multi-match-query.html#type-cross-fields" >+ - >+ - pref: EmbedHostItemsInSearchEngine >+ default: 0 >+ choices: >+ 1: Embed >+ 0: Don't embed >+ - 'host items in records in the search engine. Requires <a href="/cgi-bin/koha/admin/preferences.pl?op=search&searchfield=EasyAnalyticalRecords">EasyAnalyticalRecords</a>' > Search form: > - > - pref : LoadSearchHistoryToTheFirstLoggedUser >diff --git a/misc/migration_tools/rebuild_zebra.pl b/misc/migration_tools/rebuild_zebra.pl >index 602be76835..c491e1d3d5 100755 >--- a/misc/migration_tools/rebuild_zebra.pl >+++ b/misc/migration_tools/rebuild_zebra.pl >@@ -509,7 +509,8 @@ sub export_marc_records_from_sth { > ? GetXmlBiblio( $record_number ) > : GetAuthorityXML( $record_number ); > if ($record_type eq 'biblio'){ >- my @host_itemnumbers = C4::Items::get_hostitemnumbers_of( $record_number ); >+ my @host_itemnumbers = (); >+ @host_itemnumbers = C4::Items::get_hostitemnumbers_of( $record_number ) if C4::Context->preference('EmbedHostItemsInSearchEngine'); > my @items = Koha::Items->search({ > -or => [ > biblionumber => $record_number, >diff --git a/t/db_dependent/Items.t b/t/db_dependent/Items.t >index 5c0c121ec1..ebb578e417 100755 >--- a/t/db_dependent/Items.t >+++ b/t/db_dependent/Items.t >@@ -680,7 +680,7 @@ subtest 'Koha::Item(s) tests' => sub { > }; > > subtest 'C4::Biblio::EmbedItemsInMarcBiblio' => sub { >- plan tests => 11; >+ plan tests => 12; > > $schema->storage->txn_begin(); > >@@ -724,6 +724,7 @@ subtest 'C4::Biblio::EmbedItemsInMarcBiblio' => sub { > push @itemnumbers, $itemnumber; > } > >+ t::lib::Mocks::mock_preference( 'EasyAnalyticalRecords', '1' ); > my $host_item = $builder->build_sample_item({ homebranch => $library2->{branchcode} }); > my $child_field = PrepHostMarcField( $host_item->biblionumber, $host_item->itemnumber, 'MARC21'); > my $child_record = $biblio->metadata->record; >@@ -759,12 +760,26 @@ subtest 'C4::Biblio::EmbedItemsInMarcBiblio' => sub { > @items = $record->field($itemfield); > is( scalar @items, $number_of_items + 1, 'Should return all items plus host items' ); > >+ t::lib::Mocks::mock_preference('EmbedHostItemsInSearchEngine', '1'); > $marc_with_items = C4::Biblio::GetMarcBiblio({ > biblionumber => $biblio->biblionumber, > embed_items => 1, > embed_host_items => 1 > }); >- is_deeply( $record, $marc_with_items, 'A direct call to GetMarcBiblio with items matches'); >+ is_deeply( $record, $marc_with_items, 'A direct call to GetMarcBiblio with embed host items matches if embedding items in search engine'); >+ $record = C4::Biblio::GetMarcBiblio({ biblionumber => $biblio->biblionumber }); >+ C4::Biblio::EmbedItemsInMarcBiblio({ >+ marc_record => $record, >+ biblionumber => $biblio->biblionumber, >+ embed_host_items => 0 >+ }); >+ t::lib::Mocks::mock_preference('EmbedHostItemsInSearchEngine', '0'); >+ $marc_with_items = C4::Biblio::GetMarcBiblio({ >+ biblionumber => $biblio->biblionumber, >+ embed_items => 1, >+ embed_host_items => 1 >+ }); >+ is_deeply( $record, $marc_with_items, 'A direct call to GetMarcBiblio with embed host items does not include host item if not embedding items in search engine'); > > C4::Biblio::EmbedItemsInMarcBiblio({ > marc_record => $record, >-- >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 27138
:
114126
|
115158
|
117333
|
117334
|
117346
|
117347
|
122035
|
125698
|
125699
|
125700
|
125701
|
128175
|
128176
|
128177
|
128178
|
128179
|
139401
|
139402
|
139403
|
139404
|
144200
|
144201
|
144202
|
144203