|
Lines 45-50
use MIME::Base64;
Link Here
|
| 45 |
use Encode qw(encode); |
45 |
use Encode qw(encode); |
| 46 |
use Business::ISBN; |
46 |
use Business::ISBN; |
| 47 |
use Scalar::Util qw(looks_like_number); |
47 |
use Scalar::Util qw(looks_like_number); |
|
|
48 |
use Koha::Database; |
| 48 |
|
49 |
|
| 49 |
__PACKAGE__->mk_ro_accessors(qw( index index_name )); |
50 |
__PACKAGE__->mk_ro_accessors(qw( index index_name )); |
| 50 |
__PACKAGE__->mk_accessors(qw( sort_fields )); |
51 |
__PACKAGE__->mk_accessors(qw( sort_fields )); |
|
Lines 346-353
sub _load_elasticsearch_mappings {
Link Here
|
| 346 |
return LoadFile( $mappings_yaml ); |
347 |
return LoadFile( $mappings_yaml ); |
| 347 |
} |
348 |
} |
| 348 |
|
349 |
|
| 349 |
sub reset_elasticsearch_mappings { |
350 |
sub sync_elasticsearch_mappings { |
| 350 |
my ( $self ) = @_; |
351 |
my ($self, $options) = @_; |
|
|
352 |
$options //= {}; |
| 351 |
my $indexes = $self->_load_elasticsearch_mappings(); |
353 |
my $indexes = $self->_load_elasticsearch_mappings(); |
| 352 |
|
354 |
|
| 353 |
Koha::SearchMarcMaps->delete; |
355 |
Koha::SearchMarcMaps->delete; |
|
Lines 364-378
sub reset_elasticsearch_mappings {
Link Here
|
| 364 |
|
366 |
|
| 365 |
$sf_params{name} = $field_name; |
367 |
$sf_params{name} = $field_name; |
| 366 |
|
368 |
|
| 367 |
my $search_field = Koha::SearchFields->find_or_create( \%sf_params, { key => 'name' } ); |
369 |
my $search_field = Koha::SearchFields->find({ 'name' => $field_name }); |
| 368 |
|
370 |
if ($search_field) { |
| 369 |
my $mappings = $data->{mappings}; |
371 |
next if $options->{insert_only}; |
| 370 |
for my $mapping ( @$mappings ) { |
372 |
} |
|
|
373 |
else { |
| 374 |
my $rs = Koha::SearchFields->_resultset()->create(\%sf_params); |
| 375 |
$search_field = Koha::SearchFields->object_class->_new_from_dbic($rs); |
| 376 |
} |
| 377 |
if ($options->{revert_mappings}) { |
| 378 |
# Delete all current marc_targets for field |
| 379 |
my $rs = $search_field->_result()->search_marc_maps(); |
| 380 |
while (my $marc_map = $rs->next) { |
| 381 |
$search_field->_result()->remove_from_search_marc_maps($marc_map); |
| 382 |
# Check if other search fields uses mapping, if not delete |
| 383 |
$marc_map->delete unless (defined $marc_map->search_fields()->first); |
| 384 |
} |
| 385 |
} |
| 386 |
for my $mapping ( @{$data->{mappings}} ) { |
| 371 |
my $marc_field = Koha::SearchMarcMaps->find_or_create({ |
387 |
my $marc_field = Koha::SearchMarcMaps->find_or_create({ |
| 372 |
index_name => $index_name, |
388 |
index_name => $index_name, |
| 373 |
marc_type => $mapping->{marc_type}, |
389 |
marc_type => $mapping->{marc_type}, |
| 374 |
marc_field => $mapping->{marc_field} |
390 |
marc_field => $mapping->{marc_field} |
| 375 |
}); |
391 |
}); |
|
|
392 |
# If merging mappings relation may already exist, remove to avoid duplicate entry |
| 393 |
if(!($options->{revert_mappings} || $options->{insert_only})) { |
| 394 |
$search_field->_result()->remove_from_search_marc_maps($marc_field->_result()); |
| 395 |
} |
| 376 |
$search_field->add_to_search_marc_maps($marc_field, { |
396 |
$search_field->add_to_search_marc_maps($marc_field, { |
| 377 |
facet => $mapping->{facet} || 0, |
397 |
facet => $mapping->{facet} || 0, |
| 378 |
suggestible => $mapping->{suggestible} || 0, |
398 |
suggestible => $mapping->{suggestible} || 0, |
|
Lines 388-393
sub reset_elasticsearch_mappings {
Link Here
|
| 388 |
# FIXME return the mappings? |
408 |
# FIXME return the mappings? |
| 389 |
} |
409 |
} |
| 390 |
|
410 |
|
|
|
411 |
sub reset_elasticsearch_mappings { |
| 412 |
my $self = shift; |
| 413 |
Koha::SearchFields->search->delete; |
| 414 |
Koha::SearchMarcMaps->search->delete; |
| 415 |
$self->sync_elasticsearch_mappings(); |
| 416 |
} |
| 417 |
|
| 391 |
# This overrides the accessor provided by Class::Accessor so that if |
418 |
# This overrides the accessor provided by Class::Accessor so that if |
| 392 |
# sort_fields isn't set, then it'll generate it. |
419 |
# sort_fields isn't set, then it'll generate it. |
| 393 |
sub sort_fields { |
420 |
sub sort_fields { |