Lines 26-31
use Data::Dumper;
Link Here
|
26 |
|
26 |
|
27 |
use Koha::Exceptions; |
27 |
use Koha::Exceptions; |
28 |
use Koha::SearchEngine::Zebra::Indexer; |
28 |
use Koha::SearchEngine::Zebra::Indexer; |
|
|
29 |
use Koha::BackgroundJob::UpdateElasticIndex; |
29 |
use C4::AuthoritiesMarc qw//; |
30 |
use C4::AuthoritiesMarc qw//; |
30 |
use C4::Biblio; |
31 |
use C4::Biblio; |
31 |
use C4::Context; |
32 |
use C4::Context; |
Lines 97-108
Arrayref of C<MARC::Record>s.
Link Here
|
97 |
=cut |
98 |
=cut |
98 |
|
99 |
|
99 |
sub update_index { |
100 |
sub update_index { |
100 |
my ($self, $biblionums, $records) = @_; |
101 |
my ($self, $record_ids, $records) = @_; |
|
|
102 |
|
103 |
my $index_record_ids; |
104 |
unless ( $records && @$records ) { |
105 |
for my $record_id ( sort { $a <=> $b } @$record_ids ) { |
106 |
|
107 |
next unless $record_id; |
108 |
|
109 |
my $record = $self->_get_record( $record_id ); |
110 |
if( $record ){ |
111 |
push @$records, $record; |
112 |
push @$index_record_ids, $record_id; |
113 |
} |
114 |
} |
115 |
} else { |
116 |
$index_record_ids = $record_ids; |
117 |
} |
101 |
|
118 |
|
102 |
my $documents = $self->marc_records_to_documents($records); |
119 |
my $documents = $self->marc_records_to_documents($records); |
103 |
my @body; |
120 |
my @body; |
104 |
for (my $i = 0; $i < scalar @$biblionums; $i++) { |
121 |
for (my $i = 0; $i < scalar @$index_record_ids; $i++) { |
105 |
my $id = $biblionums->[$i]; |
122 |
my $id = $index_record_ids->[$i]; |
106 |
my $document = $documents->[$i]; |
123 |
my $document = $documents->[$i]; |
107 |
push @body, { |
124 |
push @body, { |
108 |
index => { |
125 |
index => { |
Lines 264-270
sub update_mappings {
Link Here
|
264 |
$self->set_index_status_ok(); |
281 |
$self->set_index_status_ok(); |
265 |
} |
282 |
} |
266 |
|
283 |
|
267 |
=head2 update_index_background($biblionums, $records) |
284 |
=head2 update_index_background($record_numbers, $server) |
268 |
|
285 |
|
269 |
This has exactly the same API as C<update_index> however it'll |
286 |
This has exactly the same API as C<update_index> however it'll |
270 |
return immediately. It'll start a background process that does the adding. |
287 |
return immediately. It'll start a background process that does the adding. |
Lines 274-285
it to be updated by a regular index cron job in the future.
Link Here
|
274 |
|
291 |
|
275 |
=cut |
292 |
=cut |
276 |
|
293 |
|
277 |
# TODO implement in the future - I don't know the best way of doing this yet. |
|
|
278 |
# If fork: make sure process group is changed so apache doesn't wait for us. |
279 |
|
280 |
sub update_index_background { |
294 |
sub update_index_background { |
281 |
my $self = shift; |
295 |
my ( $self, $record_numbers, $server ) = @_; |
282 |
$self->update_index(@_); |
296 |
|
|
|
297 |
Koha::BackgroundJob::UpdateElasticIndex->new->enqueue({ record_ids => $record_numbers, record_server => $server }); |
283 |
} |
298 |
} |
284 |
|
299 |
|
285 |
=head2 index_records |
300 |
=head2 index_records |
Lines 302-318
sub index_records {
Link Here
|
302 |
if ( $op eq 'specialUpdate' ) { |
317 |
if ( $op eq 'specialUpdate' ) { |
303 |
my $index_record_numbers; |
318 |
my $index_record_numbers; |
304 |
if ($records){ |
319 |
if ($records){ |
305 |
$index_record_numbers = $record_numbers; |
320 |
$self->update_index( $record_numbers, $records ); |
306 |
} else { |
321 |
} else { |
307 |
foreach my $record_number ( @$record_numbers ){ |
322 |
$self->update_index_background( $record_numbers, $server ); |
308 |
my $record = _get_record( $record_number, $server ); |
|
|
309 |
if( $record ){ |
310 |
push @$records, $record; |
311 |
push @$index_record_numbers, $record_number; |
312 |
} |
313 |
} |
314 |
} |
323 |
} |
315 |
$self->update_index_background( $index_record_numbers, $records ) if $index_record_numbers && $records; |
|
|
316 |
} |
324 |
} |
317 |
elsif ( $op eq 'recordDelete' ) { |
325 |
elsif ( $op eq 'recordDelete' ) { |
318 |
$self->delete_index_background( $record_numbers ); |
326 |
$self->delete_index_background( $record_numbers ); |
Lines 322-331
sub index_records {
Link Here
|
322 |
} |
330 |
} |
323 |
|
331 |
|
324 |
sub _get_record { |
332 |
sub _get_record { |
325 |
my ( $id, $server ) = @_; |
333 |
my ( $self, $record_id ) = @_; |
326 |
return $server eq 'biblioserver' |
334 |
return $self->index eq $Koha::SearchEngine::BIBLIOS_INDEX |
327 |
? C4::Biblio::GetMarcBiblio({ biblionumber => $id, embed_items => 1 }) |
335 |
? C4::Biblio::GetMarcBiblio({ biblionumber => $record_id, embed_items => 1 }) |
328 |
: C4::AuthoritiesMarc::GetAuthority($id); |
336 |
: C4::AuthoritiesMarc::GetAuthority($record_id); |
329 |
} |
337 |
} |
330 |
|
338 |
|
331 |
=head2 delete_index($biblionums) |
339 |
=head2 delete_index($biblionums) |