From 80f51d830ad179f541fa6f1c2e24845afe6e5d95 Mon Sep 17 00:00:00 2001 From: Nick Clemens Date: Thu, 9 Jul 2020 18:40:01 +0000 Subject: [PATCH] Bug 25273: (follow-up) Signed-off-by: Katrin Fischer --- C4/AuthoritiesMarc.pm | 2 +- C4/Biblio.pm | 10 ++++------ Koha/SearchEngine/Elasticsearch.pm | 7 ++++--- misc/search_tools/rebuild_elasticsearch.pl | 8 +++----- t/db_dependent/Koha/SearchEngine/Elasticsearch.t | 17 ++++------------- 5 files changed, 16 insertions(+), 28 deletions(-) diff --git a/C4/AuthoritiesMarc.pm b/C4/AuthoritiesMarc.pm index 94fefcdd3c..bd25837c36 100644 --- a/C4/AuthoritiesMarc.pm +++ b/C4/AuthoritiesMarc.pm @@ -628,7 +628,7 @@ sub AddAuthority { $record->insert_fields_ordered( MARC::Field->new( '001', $authid ) ); # Update $dbh->do( "UPDATE auth_header SET authtypecode=?, marc=?, marcxml=? WHERE authid=?", undef, $authtypecode, $record->as_usmarc, $record->as_xml_record($format), $authid ) or die $DBI::errstr; - ModZebra( $authid, 'specialUpdate', 'authorityserver', { record => $record, authtypecode => $authtypecode } ); + ModZebra( $authid, 'specialUpdate', 'authorityserver', $record ); return ( $authid ); } diff --git a/C4/Biblio.pm b/C4/Biblio.pm index e92f76c4f0..97fa95aeb1 100644 --- a/C4/Biblio.pm +++ b/C4/Biblio.pm @@ -2497,8 +2497,8 @@ $op is specialUpdate or recordDelete, and is used to know what we want to do $server is the server that we want to update -$record is a hash including the authtypecode and updated MARC record. This is only used for -Elasticsearch authorities. If it's not supplied a biblio will be loaded from the database. +$record is the updated MARC record. If it's not supplied +and is needed it will be loaded from the database. =cut @@ -2518,14 +2518,12 @@ sub ModZebra { } ); if ( $op eq 'specialUpdate' ) { - if ($record) { - $indexer->update_index_background( [$biblionumber], [$record] ); - } else { + unless ($record) { $record = GetMarcBiblio({ biblionumber => $biblionumber, embed_items => 1 }); - $indexer->update_index_background( [$biblionumber], [{ record => $record }] ); } + $indexer->update_index_background( [$biblionumber], [$record] ); } elsif ( $op eq 'recordDelete' ) { $indexer->delete_index_background( [$biblionumber] ); diff --git a/Koha/SearchEngine/Elasticsearch.pm b/Koha/SearchEngine/Elasticsearch.pm index f3e663e54a..a678ea2610 100644 --- a/Koha/SearchEngine/Elasticsearch.pm +++ b/Koha/SearchEngine/Elasticsearch.pm @@ -28,6 +28,7 @@ use Koha::SearchFields; use Koha::SearchMarcMaps; use Koha::Caches; use C4::Heading; +use C4::AuthoritiesMarc; use Carp; use Clone qw(clone); @@ -536,12 +537,12 @@ sub marc_records_to_documents { foreach my $record (@{$records}) { my $record_document = {}; - if ( defined $record->{authtypecode} ){ - my $field = $record->{record}->field( $auth_match_headings{ $record->{authtypecode} } ); + if ( $self->index eq 'authorities' ){ + my $authtypecode = GuessAuthTypeCode( $record ); + my $field = $record->field( $auth_match_headings{ $authtypecode } ); my $heading = C4::Heading->new_from_field( $field, undef, 1 ); #new auth heading push @{$record_document->{'match-heading'}}, $heading->search_form if $heading; } - $record = $record->{record}; my $mappings = $rules->{leader}; if ($mappings) { diff --git a/misc/search_tools/rebuild_elasticsearch.pl b/misc/search_tools/rebuild_elasticsearch.pl index 8bb6110ba1..6cff2eae2e 100755 --- a/misc/search_tools/rebuild_elasticsearch.pl +++ b/misc/search_tools/rebuild_elasticsearch.pl @@ -275,10 +275,8 @@ sub _do_reindex { my $commit_count = $commit; my ( @id_buffer, @commit_buffer ); while ( my $record = $next->() ) { - my $id = $record->id; - my $record_prepped; - $record_prepped->{authtypecode} = $record->authtypecode if ref $record eq 'Koha::MetadataRecord::Authority'; - $record_prepped->{record} = $record->record; + my $id = $record->id // $record->authid; + my $record = $record->record; $count++; if ( $verbose == 1 ) { _log( 1, "$count records processed\n" ) if ( $count % 1000 == 0); @@ -287,7 +285,7 @@ sub _do_reindex { } push @id_buffer, $id; - push @commit_buffer, $record_prepped; + push @commit_buffer, $record; if ( !( --$commit_count ) ) { _log( 1, "Committing $commit records...\n" ); my $response = $indexer->update_index( \@id_buffer, \@commit_buffer ); diff --git a/t/db_dependent/Koha/SearchEngine/Elasticsearch.t b/t/db_dependent/Koha/SearchEngine/Elasticsearch.t index 6ae3d392fa..471baf34e1 100644 --- a/t/db_dependent/Koha/SearchEngine/Elasticsearch.t +++ b/t/db_dependent/Koha/SearchEngine/Elasticsearch.t @@ -340,10 +340,7 @@ subtest 'Koha::SearchEngine::Elasticsearch::marc_records_to_documents () tests' MARC::Field->new('999', '', '', c => '1234568'), MARC::Field->new('952', '', '', 0 => 1, g => 'string where should be numeric', o => $long_callno), ); - my $records = [ - { record => $marc_record_1 }, - { record => $marc_record_2 }, - ]; + my $records = [ $marc_record_1, $marc_record_2 ]; $see->get_elasticsearch_mappings(); #sort_fields will call this and use the actual db values unless we call it first @@ -510,7 +507,7 @@ subtest 'Koha::SearchEngine::Elasticsearch::marc_records_to_documents () tests' $large_marc_record->append_fields($item_field); } - $docs = $see->marc_records_to_documents([{ record => $large_marc_record }]); + $docs = $see->marc_records_to_documents([$large_marc_record]); is($docs->[0]->{marc_format}, 'MARCXML', 'For record exceeding max record size marc_format should be set correctly'); @@ -623,10 +620,7 @@ subtest 'Koha::SearchEngine::Elasticsearch::marc_records_to_documents_array () t MARC::Field->new('999', '', '', c => '1234568'), MARC::Field->new('952', '', '', 0 => 1, g => 'string where should be numeric'), ); - my $records = [ - { record => $marc_record_1 }, - { record => $marc_record_2 }, - ]; + my $records = [ $marc_record_1, $marc_record_2 ]; $see->get_elasticsearch_mappings(); #sort_fields will call this and use the actual db values unless we call it first @@ -701,10 +695,7 @@ subtest 'Koha::SearchEngine::Elasticsearch::marc_records_to_documents () authori $marc_record_2->append_fields( MARC::Field->new('150', '', '', a => 'Subject', v => 'Genresubdiv', z => 'Geosubdiv', x => 'Generalsubdiv', e => 'wrongsubdiv' ), ); - my $records = [ - { record => $marc_record_1, authtypecode=> $auth_type->authtypecode }, - { record => $marc_record_2, authtypecode=> $auth_type->authtypecode }, - ]; + my $records = [ $marc_record_1, $marc_record_2 ]; $see->get_elasticsearch_mappings(); #sort_fields will call this and use the actual db values unless we call it first -- 2.11.0