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

(-)a/C4/Search.pm (-1 / +1 lines)
Lines 1799-1805 sub searchResults { Link Here
1799
        my $marcflavor = C4::Context->preference("marcflavour");
1799
        my $marcflavor = C4::Context->preference("marcflavour");
1800
1800
1801
        # adding linked items that belong to host records
1801
        # adding linked items that belong to host records
1802
        if ( C4::Context->preference('EasyAnalyticalRecords') ) {
1802
        if ( C4::Context->preference('EasyAnalyticalRecords') && !C4::Context->preference('EmbedHostItemsInSearchEngine') ) {
1803
            my $analyticsfield = '773';
1803
            my $analyticsfield = '773';
1804
            if ( $marcflavor eq 'MARC21' ) {
1804
            if ( $marcflavor eq 'MARC21' ) {
1805
                $analyticsfield = '773';
1805
                $analyticsfield = '773';
(-)a/C4/XSLT.pm (-1 / +2 lines)
Lines 281-287 Is only used in this module currently. Link Here
281
sub buildKohaItemsNamespace {
281
sub buildKohaItemsNamespace {
282
    my ( $biblionumber, $hidden_items, $items_rs ) = @_;
282
    my ( $biblionumber, $hidden_items, $items_rs ) = @_;
283
283
284
    my @host_itemnumbers = C4::Items::get_hostitemnumbers_of( $biblionumber );
284
    my @host_itemnumbers = ();
285
    @host_itemnumbers = C4::Items::get_hostitemnumbers_of( $biblionumber ) if C4::Context->preference('EmbedHostItemsInSearchEngine');
285
    $hidden_items ||= [];
286
    $hidden_items ||= [];
286
287
287
    my $query = {};
288
    my $query = {};
(-)a/Koha/Biblio/Metadata.pm (-22 / +14 lines)
Lines 20-28 use Modern::Perl; Link Here
20
use MARC::File::XML;
20
use MARC::File::XML;
21
use Scalar::Util qw( blessed );
21
use Scalar::Util qw( blessed );
22
22
23
use C4::Biblio qw( GetMarcFromKohaField );
23
use C4::Biblio  qw( GetMarcFromKohaField );
24
use C4::Charset qw( StripNonXmlChars );
24
use C4::Charset qw( StripNonXmlChars );
25
use C4::Items qw( GetMarcItem get_hostitemnumbers_of );
25
use C4::Items   qw( GetMarcItem get_hostitemnumbers_of );
26
26
27
use Koha::Database;
27
use Koha::Database;
28
use Koha::Exceptions::Metadata;
28
use Koha::Exceptions::Metadata;
Lines 227-257 sub _embed_items { Link Here
227
227
228
    if ( $format eq 'marcxml' ) {
228
    if ( $format eq 'marcxml' ) {
229
229
230
<<<<<<< HEAD
231
        my ( $itemtag, $itemsubfield ) = C4::Biblio::GetMarcFromKohaField("items.itemnumber");
232
        my $biblio = Koha::Biblios->find($biblionumber);
233
234
        my $items = $biblio->items;
235
        if (@$itemnumbers) {
236
            $items = $items->search( { itemnumber => { -in => $itemnumbers } } );
237
=======
238
        # First remove the existing items from the MARC record
230
        # First remove the existing items from the MARC record
239
        my ( $itemtag, $itemsubfield ) = C4::Biblio::GetMarcFromKohaField( "items.itemnumber" );
231
        my ( $itemtag, $itemsubfield ) = C4::Biblio::GetMarcFromKohaField("items.itemnumber");
240
        foreach my $field ( $record->field($itemtag) ) {
232
        foreach my $field ( $record->field($itemtag) ) {
241
            $record->delete_field($field);
233
            $record->delete_field($field);
242
        }
234
        }
243
235
244
        push @$itemnumbers, C4::Items::get_hostitemnumbers_of( $biblionumber ) if $params->{embed_host_items};
236
        push @$itemnumbers, C4::Items::get_hostitemnumbers_of($biblionumber)
245
237
            if $params->{embed_host_items} && C4::Context->preference('EmbedHostItemsInSearchEngine');
246
        my $items = Koha::Items->search([
238
247
           'me.biblionumber' => $biblionumber,
239
        my $items = Koha::Items->search(
248
           'me.itemnumber' => {
240
            [
249
              -in => $itemnumbers
241
                'me.biblionumber' => $biblionumber,
250
              }
242
                'me.itemnumber'   => { -in => $itemnumbers }
251
        ]);
243
            ]
252
        if ( @$itemnumbers ) {
244
        );
253
            $items = $items->search({ itemnumber => { -in => $itemnumbers } });
245
        if (@$itemnumbers) {
254
>>>>>>> Bug 27138: Index host items in child records when sending to search engine
246
            $items = $items->search( { itemnumber => { -in => $itemnumbers } } );
255
        }
247
        }
256
        if ($opac) {
248
        if ($opac) {
257
            $items = $items->filter_by_visible_in_opac( { patron => $patron } );
249
            $items = $items->filter_by_visible_in_opac( { patron => $patron } );
(-)a/installer/data/mysql/mandatory/sysprefs.sql (+1 lines)
Lines 250-255 INSERT INTO systempreferences ( `variable`, `value`, `options`, `explanation`, ` Link Here
250
('EmailPatronWhenHoldIsPlaced', '0', NULL, 'Email patron when a hold has been placed for them', 'YesNo'),
250
('EmailPatronWhenHoldIsPlaced', '0', NULL, 'Email patron when a hold has been placed for them', 'YesNo'),
251
('EmailPurchaseSuggestions','0','0|EmailAddressForSuggestions|BranchEmailAddress|KohaAdminEmailAddress','Choose email address that new purchase suggestions will be sent to: ','Choice'),
251
('EmailPurchaseSuggestions','0','0|EmailAddressForSuggestions|BranchEmailAddress|KohaAdminEmailAddress','Choose email address that new purchase suggestions will be sent to: ','Choice'),
252
('EmailSMSSendDriverFromAddress', '', '', 'Email SMS send driver from address override', 'Free'),
252
('EmailSMSSendDriverFromAddress', '', '', 'Email SMS send driver from address override', 'Free'),
253
('EmbedHostItemsInSearchEngine','0','','Add host items to records in the search engine','YesNo'),
253
('EnableAdvancedCatalogingEditor','0','','Enable the Rancor advanced cataloging editor','YesNo'),
254
('EnableAdvancedCatalogingEditor','0','','Enable the Rancor advanced cataloging editor','YesNo'),
254
('EnableBorrowerFiles','0',NULL,'If enabled, allows librarians to upload and attach arbitrary files to a borrower record.','YesNo'),
255
('EnableBorrowerFiles','0',NULL,'If enabled, allows librarians to upload and attach arbitrary files to a borrower record.','YesNo'),
255
('EnableExpiredPasswordReset', '0', NULL, 'Enable ability for patrons with expired password to reset their password directly', 'YesNo'),
256
('EnableExpiredPasswordReset', '0', NULL, 'Enable ability for patrons with expired password to reset their password directly', 'YesNo'),
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/searching.pref (+7 lines)
Lines 131-136 Searching: Link Here
131
            - "<pre>ccode: [REF,ARC]</pre><br/>  - would mark all REF and ARC collections (Reference and Archives) items as unavailable in Z3950 results.<br/><br/>"
131
            - "<pre>ccode: [REF,ARC]</pre><br/>  - would mark all REF and ARC collections (Reference and Archives) items as unavailable in Z3950 results.<br/><br/>"
132
            - "You can define multiple keys and values, items meeting ANY of the criteria will be marked unavailable:<br/><br/>"
132
            - "You can define multiple keys and values, items meeting ANY of the criteria will be marked unavailable:<br/><br/>"
133
            - "<pre>itype: [REF]<br/>holdingbranch: [REPAIR]</pre><br/>  - would mark all reference items AND items at the REPAIR branch as unavailable."
133
            - "<pre>itype: [REF]<br/>holdingbranch: [REPAIR]</pre><br/>  - would mark all reference items AND items at the REPAIR branch as unavailable."
134
        -
135
            - pref: EmbedHostItemsInSearchEngine
136
              default: 0
137
              choices:
138
                  1: Embed
139
                  0: Don't embed
140
            - 'host items in records in the search engine. Requires <a href="/cgi-bin/koha/admin/preferences.pl?op=search&searchfield=EasyAnalyticalRecords">EasyAnalyticalRecords</a>'
134
    Search form:
141
    Search form:
135
        -
142
        -
136
            - pref: LoadSearchHistoryToTheFirstLoggedUser
143
            - pref: LoadSearchHistoryToTheFirstLoggedUser
(-)a/misc/migration_tools/rebuild_zebra.pl (-15 / +3 lines)
Lines 583-589 sub export_marc_records_from_sth { Link Here
583
            if ( $record_type eq 'biblio' ) {
583
            if ( $record_type eq 'biblio' ) {
584
                my $biblio = Koha::Biblios->find($record_number);
584
                my $biblio = Koha::Biblios->find($record_number);
585
                next unless $biblio;
585
                next unless $biblio;
586
                my @host_itemnumbers = C4::Items::get_hostitemnumbers_of( $record_number );
586
                my @host_itemnumbers = ();
587
                @host_itemnumbers = C4::Items::get_hostitemnumbers_of( $record_number ) if C4::Context->preference('EmbedHostItemsInSearchEngine');
587
                my $items = Koha::Items->search({
588
                my $items = Koha::Items->search({
588
                    -or => [
589
                    -or => [
589
                        biblionumber => $record_number,
590
                        biblionumber => $record_number,
Lines 773-797 sub get_raw_marc_record { Link Here
773
    my ( $record_type, $record_number ) = @_;
774
    my ( $record_type, $record_number ) = @_;
774
775
775
    my $marc;
776
    my $marc;
776
<<<<<<< HEAD
777
    if ( $record_type eq 'biblio' ) {
777
    if ( $record_type eq 'biblio' ) {
778
=======
779
    if ($record_type eq 'biblio') {
780
<<<<<<< HEAD
781
>>>>>>> Bug 27138: Index host items in child records when sending to search engine
782
        eval {
778
        eval {
783
            my $biblio = Koha::Biblios->find($record_number);
779
            my $biblio = Koha::Biblios->find($record_number);
784
            $marc = $biblio->metadata_record( { embed_items => 1 } );
780
            $marc = $biblio->metadata->record({ embed_items => 1, embed_host_items => 1 });
785
        };
781
        };
786
<<<<<<< HEAD
787
        if ( $@ || !$marc ) {
788
789
=======
790
=======
791
        eval { $marc = C4::Biblio::GetMarcBiblio({ biblionumber => $record_number, embed_items => 1, embed_host_items => 1 }); };
792
>>>>>>> Bug 27138: Index host items in child records when sending to search engine
793
        if ($@ || !$marc) {
782
        if ($@ || !$marc) {
794
>>>>>>> Bug 27138: Index host items in child records when sending to search engine
795
            # here we do warn since catching an exception
783
            # here we do warn since catching an exception
796
            # means that the bib was found but failed
784
            # means that the bib was found but failed
797
            # to be parsed
785
            # to be parsed
(-)a/t/db_dependent/Items.t (-3 / +17 lines)
Lines 725-731 subtest 'Koha::Item(s) tests' => sub { Link Here
725
};
725
};
726
726
727
subtest 'C4::Biblio::EmbedItemsInMarcBiblio' => sub {
727
subtest 'C4::Biblio::EmbedItemsInMarcBiblio' => sub {
728
    plan tests => 11;
728
    plan tests => 12;
729
729
730
    $schema->storage->txn_begin();
730
    $schema->storage->txn_begin();
731
731
Lines 769-774 subtest 'C4::Biblio::EmbedItemsInMarcBiblio' => sub { Link Here
769
        push @itemnumbers, $itemnumber;
769
        push @itemnumbers, $itemnumber;
770
    }
770
    }
771
771
772
    t::lib::Mocks::mock_preference( 'EasyAnalyticalRecords', '1' );
772
    my $host_item = $builder->build_sample_item({ homebranch => $library2->{branchcode} });
773
    my $host_item = $builder->build_sample_item({ homebranch => $library2->{branchcode} });
773
    my $child_field = PrepHostMarcField( $host_item->biblionumber, $host_item->itemnumber, 'MARC21');
774
    my $child_field = PrepHostMarcField( $host_item->biblionumber, $host_item->itemnumber, 'MARC21');
774
    my $child_record = $biblio->metadata->record;
775
    my $child_record = $biblio->metadata->record;
Lines 804-815 subtest 'C4::Biblio::EmbedItemsInMarcBiblio' => sub { Link Here
804
    @items = $record->field($itemfield);
805
    @items = $record->field($itemfield);
805
    is( scalar @items, $number_of_items + 1, 'Should return all items plus host items' );
806
    is( scalar @items, $number_of_items + 1, 'Should return all items plus host items' );
806
807
808
    t::lib::Mocks::mock_preference('EmbedHostItemsInSearchEngine', '1');
807
    $marc_with_items = C4::Biblio::GetMarcBiblio({
809
    $marc_with_items = C4::Biblio::GetMarcBiblio({
808
        biblionumber => $biblio->biblionumber,
810
        biblionumber => $biblio->biblionumber,
809
        embed_items  => 1,
811
        embed_items  => 1,
810
        embed_host_items => 1
812
        embed_host_items => 1
811
    });
813
    });
812
    is_deeply( $record, $marc_with_items, 'A direct call to GetMarcBiblio with items matches');
814
    is_deeply( $record, $marc_with_items, 'A direct call to GetMarcBiblio with embed host items matches if embedding items in search engine');
815
    $record = C4::Biblio::GetMarcBiblio({ biblionumber => $biblio->biblionumber });
816
    C4::Biblio::EmbedItemsInMarcBiblio({
817
        marc_record  => $record,
818
        biblionumber => $biblio->biblionumber,
819
        embed_host_items => 0
820
    });
821
    t::lib::Mocks::mock_preference('EmbedHostItemsInSearchEngine', '0');
822
    $marc_with_items = C4::Biblio::GetMarcBiblio({
823
        biblionumber => $biblio->biblionumber,
824
        embed_items  => 1,
825
        embed_host_items => 1
826
    });
827
    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');
813
828
814
    C4::Biblio::EmbedItemsInMarcBiblio({
829
    C4::Biblio::EmbedItemsInMarcBiblio({
815
        marc_record  => $record,
830
        marc_record  => $record,
816
- 

Return to bug 27138