|
Lines 26-31
use base qw(Koha::SearchEngine::Elasticsearch);
Link Here
|
| 26 |
use Koha::Exceptions; |
26 |
use Koha::Exceptions; |
| 27 |
use Koha::Exceptions::Elasticsearch; |
27 |
use Koha::Exceptions::Elasticsearch; |
| 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 271-277
sub update_mappings {
Link Here
|
| 271 |
$self->set_index_status_ok(); |
288 |
$self->set_index_status_ok(); |
| 272 |
} |
289 |
} |
| 273 |
|
290 |
|
| 274 |
=head2 update_index_background($biblionums, $records) |
291 |
=head2 update_index_background($record_numbers, $server) |
| 275 |
|
292 |
|
| 276 |
This has exactly the same API as C<update_index> however it'll |
293 |
This has exactly the same API as C<update_index> however it'll |
| 277 |
return immediately. It'll start a background process that does the adding. |
294 |
return immediately. It'll start a background process that does the adding. |
|
Lines 281-292
it to be updated by a regular index cron job in the future.
Link Here
|
| 281 |
|
298 |
|
| 282 |
=cut |
299 |
=cut |
| 283 |
|
300 |
|
| 284 |
# TODO implement in the future - I don't know the best way of doing this yet. |
|
|
| 285 |
# If fork: make sure process group is changed so apache doesn't wait for us. |
| 286 |
|
| 287 |
sub update_index_background { |
301 |
sub update_index_background { |
| 288 |
my $self = shift; |
302 |
my ( $self, $record_numbers, $server ) = @_; |
| 289 |
$self->update_index(@_); |
303 |
|
|
|
304 |
Koha::BackgroundJob::UpdateElasticIndex->new->enqueue({ record_ids => $record_numbers, record_server => $server }); |
| 290 |
} |
305 |
} |
| 291 |
|
306 |
|
| 292 |
=head2 index_records |
307 |
=head2 index_records |
|
Lines 307-325
sub index_records {
Link Here
|
| 307 |
$record_numbers = [$record_numbers] if ref $record_numbers ne 'ARRAY' && defined $record_numbers; |
322 |
$record_numbers = [$record_numbers] if ref $record_numbers ne 'ARRAY' && defined $record_numbers; |
| 308 |
$records = [$records] if ref $records ne 'ARRAY' && defined $records; |
323 |
$records = [$records] if ref $records ne 'ARRAY' && defined $records; |
| 309 |
if ( $op eq 'specialUpdate' ) { |
324 |
if ( $op eq 'specialUpdate' ) { |
| 310 |
my $index_record_numbers; |
|
|
| 311 |
if ($records){ |
325 |
if ($records){ |
| 312 |
$index_record_numbers = $record_numbers; |
326 |
$self->update_index( $record_numbers, $records ); |
| 313 |
} else { |
327 |
} else { |
| 314 |
foreach my $record_number ( @$record_numbers ){ |
328 |
$self->update_index_background( $record_numbers, $server ); |
| 315 |
my $record = _get_record( $record_number, $server ); |
|
|
| 316 |
if( $record ){ |
| 317 |
push @$records, $record; |
| 318 |
push @$index_record_numbers, $record_number; |
| 319 |
} |
| 320 |
} |
| 321 |
} |
329 |
} |
| 322 |
$self->update_index_background( $index_record_numbers, $records ) if $index_record_numbers && $records; |
|
|
| 323 |
} |
330 |
} |
| 324 |
elsif ( $op eq 'recordDelete' ) { |
331 |
elsif ( $op eq 'recordDelete' ) { |
| 325 |
$self->delete_index_background( $record_numbers ); |
332 |
$self->delete_index_background( $record_numbers ); |
|
Lines 329-338
sub index_records {
Link Here
|
| 329 |
} |
336 |
} |
| 330 |
|
337 |
|
| 331 |
sub _get_record { |
338 |
sub _get_record { |
| 332 |
my ( $id, $server ) = @_; |
339 |
my ( $self, $record_id ) = @_; |
| 333 |
return $server eq 'biblioserver' |
340 |
return $self->index eq $Koha::SearchEngine::BIBLIOS_INDEX |
| 334 |
? C4::Biblio::GetMarcBiblio({ biblionumber => $id, embed_items => 1 }) |
341 |
? C4::Biblio::GetMarcBiblio({ biblionumber => $record_id, embed_items => 1 }) |
| 335 |
: C4::AuthoritiesMarc::GetAuthority($id); |
342 |
: C4::AuthoritiesMarc::GetAuthority($record_id); |
| 336 |
} |
343 |
} |
| 337 |
|
344 |
|
| 338 |
=head2 delete_index($biblionums) |
345 |
=head2 delete_index($biblionums) |