}
# TODO: Perhaps should check if $records_document non empty, but really should never be the case
$record->encoding('UTF-8');
- if ($serialization_format eq 'base64ISO2709') {
+ my @warnings;
+ {
+ # Temporarily intercept all warn signals (MARC::Record carps when record length > 99999)
+ local $SIG{__WARN__} = sub {
+ push @warnings, $_[0];
+ };
$record_document->{'marc_data'} = encode_base64(encode('UTF-8', $record->as_usmarc()));
}
- else {
+ if (@warnings) {
+ # Suppress warnings if record length exceeded
+ unless (substr($record->leader(), 0, 5) eq '99999') {
+ foreach my $warning (@warnings) {
+ carp($warning);
+ }
+ }
$record_document->{'marc_data'} = $record->as_xml_record($marcflavour);
+ $record_document->{'marc_format'} = 'MARCXML';
+ }
+ else {
+ $record_document->{'marc_format'} = 'base64ISO2709';
}
my $id = $record->subfield('999', 'c');
push @record_documents, [$id, $record_document];
# Result is passed in as array, will get flattened
# and first element will be $result
my ( $self, $result ) = @_;
- if (C4::Context->preference('ElasticsearchMARCSerializationFormat') eq 'MARCXML') {
+ if ($result->{marc_format} eq 'base64ISO2709') {
+ return MARC::Record->new_from_usmarc(decode_base64($result->{marc_data}));
+ }
+ elsif ($result->{marc_format} eq 'MARCXML') {
return MARC::Record->new_from_xml($result->{marc_data}, 'UTF-8', uc C4::Context->preference('marcflavour'));
}
else {
- return MARC::Record->new_from_usmarc(decode_base64($result->{marc_data}));
+ die("Missing marc_format field in Elasticsearch result");
}
}
choices:
Zebra: Zebra
Elasticsearch: Elasticsearch
- -
- - "Use"
- - pref: ElasticsearchMARCSerializationFormat
- default: MARCXML
- choices:
- MARCXML: MARCXML
- base64ISO2709: base64ISO2709
- - "as serialization format for MARC records stored in Elasticsearch index. base64ISO2709 is faster and will use less space but have a maximum record length which could cause issues with very large records."