@@ -, +, @@ request --- C4/Biblio.pm | 14 ++++++++++---- Koha/BackgroundJob/BatchUpdateBiblio.pm | 8 +++++++- Koha/Items.pm | 11 ++++++----- Koha/SearchEngine/Elasticsearch/Indexer.pm | 13 +++++++++++-- 4 files changed, 34 insertions(+), 12 deletions(-) --- a/C4/Biblio.pm +++ a/C4/Biblio.pm @@ -351,7 +351,9 @@ Returns 1 on success 0 on failure sub ModBiblio { my ( $record, $biblionumber, $frameworkcode, $options ) = @_; + $options //= {}; + my $skip_record_index = $options->{skip_record_index} || 0; if (!$record) { carp 'No record passed to ModBiblio'; @@ -415,7 +417,7 @@ sub ModBiblio { _koha_marc_update_biblioitem_cn_sort( $record, $oldbiblio, $frameworkcode ); # update the MARC record (that now contains biblio and items) with the new record data - ModBiblioMarc( $record, $biblionumber ); + ModBiblioMarc( $record, $biblionumber, { skip_record_index => $skip_record_index } ); # modify the other koha tables _koha_modify_biblio( $dbh, $oldbiblio, $frameworkcode ); @@ -2852,12 +2854,14 @@ Function exported, but should NOT be used, unless you really know what you're do sub ModBiblioMarc { # pass the MARC::Record to this function, and it will create the records in # the marcxml field - my ( $record, $biblionumber ) = @_; + my ( $record, $biblionumber, $params ) = @_; if ( !$record ) { carp 'ModBiblioMarc passed an undefined record'; return; } + my $skip_record_index = $params->{skip_record_index} || 0; + # Clone record as it gets modified $record = $record->clone(); my $dbh = C4::Context->dbh; @@ -2917,8 +2921,10 @@ sub ModBiblioMarc { $m_rs->metadata( $record->as_xml_record($encoding) ); $m_rs->store; - my $indexer = Koha::SearchEngine::Indexer->new({ index => $Koha::SearchEngine::BIBLIOS_INDEX }); - $indexer->index_records( $biblionumber, "specialUpdate", "biblioserver" ); + unless ( $skip_record_index ) { + my $indexer = Koha::SearchEngine::Indexer->new({ index => $Koha::SearchEngine::BIBLIOS_INDEX }); + $indexer->index_records( $biblionumber, "specialUpdate", "biblioserver" ); + } return $biblionumber; } --- a/Koha/BackgroundJob/BatchUpdateBiblio.pm +++ a/Koha/BackgroundJob/BatchUpdateBiblio.pm @@ -20,6 +20,8 @@ use JSON qw( decode_json encode_json ); use Koha::DateUtils qw( dt_from_string ); use Koha::Virtualshelves; +use Koha::SearchEngine; +use Koha::SearchEngine::Indexer; use C4::Context; use C4::Biblio; @@ -89,7 +91,8 @@ sub process { C4::MarcModificationTemplates::ModifyRecordWithTemplate( $mmtid, $record ); my $frameworkcode = C4::Biblio::GetFrameworkCode( $biblionumber ); C4::Biblio::ModBiblio( $record, $biblionumber, $frameworkcode, { - overlay_context => $args->{overlay_context}, + overlay_context => $args->{overlay_context}, + skip_record_index => 1, }); }; if ( $error and $error != 1 or $@ ) { # ModBiblio returns 1 if everything as gone well @@ -110,6 +113,9 @@ sub process { $self->progress( ++$job_progress )->store; } + my $indexer = Koha::SearchEngine::Indexer->new({ index => $Koha::SearchEngine::BIBLIOS_INDEX }); + $indexer->index_records( \@record_ids, "specialUpdate", "biblioserver", undef, { index_now => 1 } ); + my $job_data = decode_json $self->data; $job_data->{messages} = \@messages; $job_data->{report} = $report; --- a/Koha/Items.pm +++ a/Koha/Items.pm @@ -353,11 +353,12 @@ sub batch_update { Koha::Items->search( { itemnumber => \@modified_itemnumbers } ) ->get_column('biblionumber')); - my $indexer = Koha::SearchEngine::Indexer->new( - { index => $Koha::SearchEngine::BIBLIOS_INDEX } ); - $indexer->index_records( \@biblionumbers, 'specialUpdate', - "biblioserver", undef ) - if @biblionumbers; + if ( @biblionumbers ) { + my $indexer = Koha::SearchEngine::Indexer->new( + { index => $Koha::SearchEngine::BIBLIOS_INDEX } ); + + $indexer->update_index( \@biblionumbers ); + } } return ( { modified_itemnumbers => \@modified_itemnumbers, modified_fields => $modified_fields }, $self ); --- a/Koha/SearchEngine/Elasticsearch/Indexer.pm +++ a/Koha/SearchEngine/Elasticsearch/Indexer.pm @@ -315,14 +315,23 @@ at the moment. The other variables are used for parity with Zebra indexing calls. Currently the calls are passed through to Zebra as well. +=item C<$more_params> + +index_now can be set to force indexation on the fly. + +=back + =cut sub index_records { - my ( $self, $record_numbers, $op, $server, $records ) = @_; + my ( $self, $record_numbers, $op, $server, $records, $more_params ) = @_; $record_numbers = [$record_numbers] if ref $record_numbers ne 'ARRAY' && defined $record_numbers; $records = [$records] if ref $records ne 'ARRAY' && defined $records; + + my $index_now = $more_params->{index_now} || 0; + if ( $op eq 'specialUpdate' ) { - if ($records){ + if ( $records || $index_now ) { $self->update_index( $record_numbers, $records ); } else { $self->update_index_background( $record_numbers, $server ); --