|
Lines 310-318
sub sort_fields {
Link Here
|
| 310 |
return $self->_sort_fields_accessor(); |
310 |
return $self->_sort_fields_accessor(); |
| 311 |
} |
311 |
} |
| 312 |
|
312 |
|
| 313 |
=head2 _process_mappings($mappings, $data, $record_document) |
313 |
=head2 _process_mappings($mappings, $data, $record_document, $altscript) |
| 314 |
|
314 |
|
| 315 |
$self->_process_mappings($mappings, $marc_field_data, $record_document) |
315 |
$self->_process_mappings($mappings, $marc_field_data, $record_document, 0) |
| 316 |
|
316 |
|
| 317 |
Process all C<$mappings> targets operating on a specific MARC field C<$data>. |
317 |
Process all C<$mappings> targets operating on a specific MARC field C<$data>. |
| 318 |
Since we group all mappings by MARC field targets C<$mappings> will contain |
318 |
Since we group all mappings by MARC field targets C<$mappings> will contain |
|
Lines 338-351
The source data from a MARC record field.
Link Here
|
| 338 |
Hashref representing the Elasticsearch document on which mappings should be |
338 |
Hashref representing the Elasticsearch document on which mappings should be |
| 339 |
applied. |
339 |
applied. |
| 340 |
|
340 |
|
|
|
341 |
=item C<$altscript> |
| 342 |
|
| 343 |
A boolean value indicating whether an alternate script presentation is being |
| 344 |
processed. |
| 345 |
|
| 341 |
=back |
346 |
=back |
| 342 |
|
347 |
|
| 343 |
=cut |
348 |
=cut |
| 344 |
|
349 |
|
| 345 |
sub _process_mappings { |
350 |
sub _process_mappings { |
| 346 |
my ($_self, $mappings, $data, $record_document) = @_; |
351 |
my ($_self, $mappings, $data, $record_document, $altscript) = @_; |
| 347 |
foreach my $mapping (@{$mappings}) { |
352 |
foreach my $mapping (@{$mappings}) { |
| 348 |
my ($target, $options) = @{$mapping}; |
353 |
my ($target, $options) = @{$mapping}; |
|
|
354 |
|
| 355 |
# Don't process sort fields for alternate scripts |
| 356 |
my $sort = $target =~ /__sort$/; |
| 357 |
if ($sort && $altscript) { |
| 358 |
next; |
| 359 |
} |
| 360 |
|
| 349 |
# Copy (scalar) data since can have multiple targets |
361 |
# Copy (scalar) data since can have multiple targets |
| 350 |
# with differing options for (possibly) mutating data |
362 |
# with differing options for (possibly) mutating data |
| 351 |
# so need a different copy for each |
363 |
# so need a different copy for each |
|
Lines 363-369
sub _process_mappings {
Link Here
|
| 363 |
$options->{property} => $_data |
375 |
$options->{property} => $_data |
| 364 |
} |
376 |
} |
| 365 |
} |
377 |
} |
| 366 |
push @{$record_document->{$target}}, $_data; |
378 |
# For sort fields, index only a single field with concatenated values |
|
|
379 |
if ($sort && @{$record_document->{$target}}) { |
| 380 |
@{$record_document->{$target}}[0] .= " $_data"; |
| 381 |
} else { |
| 382 |
push @{$record_document->{$target}}, $_data; |
| 383 |
} |
| 367 |
} |
384 |
} |
| 368 |
} |
385 |
} |
| 369 |
|
386 |
|
|
Lines 399-415
sub marc_records_to_documents {
Link Here
|
| 399 |
my $record_document = {}; |
416 |
my $record_document = {}; |
| 400 |
my $mappings = $rules->{leader}; |
417 |
my $mappings = $rules->{leader}; |
| 401 |
if ($mappings) { |
418 |
if ($mappings) { |
| 402 |
$self->_process_mappings($mappings, $record->leader(), $record_document); |
419 |
$self->_process_mappings($mappings, $record->leader(), $record_document, 0); |
| 403 |
} |
420 |
} |
| 404 |
foreach my $field ($record->fields()) { |
421 |
foreach my $field ($record->fields()) { |
| 405 |
if($field->is_control_field()) { |
422 |
if ($field->is_control_field()) { |
| 406 |
my $mappings = $control_fields_rules->{$field->tag()}; |
423 |
my $mappings = $control_fields_rules->{$field->tag()}; |
| 407 |
if ($mappings) { |
424 |
if ($mappings) { |
| 408 |
$self->_process_mappings($mappings, $field->data(), $record_document); |
425 |
$self->_process_mappings($mappings, $field->data(), $record_document, 0); |
| 409 |
} |
426 |
} |
| 410 |
} |
427 |
} |
| 411 |
else { |
428 |
else { |
| 412 |
my $data_field_rules = $data_fields_rules->{$field->tag()}; |
429 |
my $tag = $field->tag(); |
|
|
430 |
# Handle alternate scripts in MARC 21 |
| 431 |
my $altscript = 0; |
| 432 |
if ($marcflavour eq 'marc21' && $tag eq '880') { |
| 433 |
my $sub6 = $field->subfield('6'); |
| 434 |
if ($sub6 =~ /^(...)-\d+/) { |
| 435 |
$tag = $1; |
| 436 |
$altscript = 1; |
| 437 |
} |
| 438 |
} |
| 439 |
|
| 440 |
my $data_field_rules = $data_fields_rules->{$tag}; |
| 413 |
|
441 |
|
| 414 |
if ($data_field_rules) { |
442 |
if ($data_field_rules) { |
| 415 |
my $subfields_mappings = $data_field_rules->{subfields}; |
443 |
my $subfields_mappings = $data_field_rules->{subfields}; |
|
Lines 421-427
sub marc_records_to_documents {
Link Here
|
| 421 |
$mappings = [@{$mappings}, @{$wildcard_mappings}]; |
449 |
$mappings = [@{$mappings}, @{$wildcard_mappings}]; |
| 422 |
} |
450 |
} |
| 423 |
if (@{$mappings}) { |
451 |
if (@{$mappings}) { |
| 424 |
$self->_process_mappings($mappings, $data, $record_document); |
452 |
$self->_process_mappings($mappings, $data, $record_document, $altscript); |
| 425 |
} |
453 |
} |
| 426 |
} |
454 |
} |
| 427 |
|
455 |
|
|
Lines 437-443
sub marc_records_to_documents {
Link Here
|
| 437 |
) |
465 |
) |
| 438 |
); |
466 |
); |
| 439 |
if ($data) { |
467 |
if ($data) { |
| 440 |
$self->_process_mappings($subfields_join_mappings->{$subfields_group}, $data, $record_document); |
468 |
$self->_process_mappings($subfields_join_mappings->{$subfields_group}, $data, $record_document, $altscript); |
| 441 |
} |
469 |
} |
| 442 |
} |
470 |
} |
| 443 |
} |
471 |
} |