View | Details | Raw Unified | Return to bug 19893
Collapse All | Expand All

(-)a/Koha/SearchEngine/Elasticsearch.pm (-2 / +17 lines)
Lines 379-389 sub marc_records_to_documents { Link Here
379
        }
379
        }
380
        # TODO: Perhaps should check if $records_document non empty, but really should never be the case
380
        # TODO: Perhaps should check if $records_document non empty, but really should never be the case
381
        $record->encoding('UTF-8');
381
        $record->encoding('UTF-8');
382
        if ($serialization_format eq 'base64ISO2709') {
382
        my @warnings;
383
        {
384
            # Temporarily intercept all warn signals (MARC::Record carps when record length > 99999)
385
            local $SIG{__WARN__} = sub {
386
                push @warnings, $_[0];
387
            };
383
            $record_document->{'marc_data'} = encode_base64(encode('UTF-8', $record->as_usmarc()));
388
            $record_document->{'marc_data'} = encode_base64(encode('UTF-8', $record->as_usmarc()));
384
        }
389
        }
385
        else {
390
        if (@warnings) {
391
            # Suppress warnings if record length exceeded
392
            unless (substr($record->leader(), 0, 5) eq '99999') {
393
                foreach my $warning (@warnings) {
394
                    carp($warning);
395
                }
396
            }
386
            $record_document->{'marc_data'} = $record->as_xml_record($marcflavour);
397
            $record_document->{'marc_data'} = $record->as_xml_record($marcflavour);
398
            $record_document->{'marc_format'} = 'MARCXML';
399
        }
400
        else {
401
            $record_document->{'marc_format'} = 'base64ISO2709';
387
        }
402
        }
388
        my $id = $record->subfield('999', 'c');
403
        my $id = $record->subfield('999', 'c');
389
        push @record_documents, [$id, $record_document];
404
        push @record_documents, [$id, $record_document];
(-)a/Koha/SearchEngine/Elasticsearch/Search.pm (-2 / +5 lines)
Lines 369-379 sub decode_record_from_result { Link Here
369
    # Result is passed in as array, will get flattened
369
    # Result is passed in as array, will get flattened
370
    # and first element will be $result
370
    # and first element will be $result
371
    my ( $self, $result ) = @_;
371
    my ( $self, $result ) = @_;
372
    if (C4::Context->preference('ElasticsearchMARCSerializationFormat') eq 'MARCXML') {
372
    if ($result->{marc_format} eq 'base64ISO2709') {
373
        return MARC::Record->new_from_usmarc(decode_base64($result->{marc_data}));
374
    }
375
    elsif ($result->{marc_format} eq 'MARCXML') {
373
        return MARC::Record->new_from_xml($result->{marc_data}, 'UTF-8', uc C4::Context->preference('marcflavour'));
376
        return MARC::Record->new_from_xml($result->{marc_data}, 'UTF-8', uc C4::Context->preference('marcflavour'));
374
    }
377
    }
375
    else {
378
    else {
376
        return MARC::Record->new_from_usmarc(decode_base64($result->{marc_data}));
379
        die("Missing marc_format field in Elasticsearch result");
377
    }
380
    }
378
}
381
}
379
382
(-)a/admin/searchengine/elasticsearch/field_config.yaml (+6 lines)
Lines 10-15 general: Link Here
10
      type: text
10
      type: text
11
      analyzer: keyword
11
      analyzer: keyword
12
      index: false
12
      index: false
13
    marc_format:
14
      store: true
15
      type: text
16
      analyzer: keyword
17
      index: false
18
13
# Search fields
19
# Search fields
14
search:
20
search:
15
  boolean:
21
  boolean:
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/admin.pref (-9 lines)
Lines 427-437 Administration: Link Here
427
              choices:
427
              choices:
428
                Zebra: Zebra
428
                Zebra: Zebra
429
                Elasticsearch: Elasticsearch
429
                Elasticsearch: Elasticsearch
430
        -
431
            - "Use"
432
            - pref: ElasticsearchMARCSerializationFormat
433
              default: MARCXML
434
              choices:
435
                MARCXML: MARCXML
436
                base64ISO2709: base64ISO2709
437
            - "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."
438
- 

Return to bug 19893