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 368-378 sub decode_record_from_result { Link Here
368
    # Result is passed in as array, will get flattened
368
    # Result is passed in as array, will get flattened
369
    # and first element will be $result
369
    # and first element will be $result
370
    my ( $self, $result ) = @_;
370
    my ( $self, $result ) = @_;
371
    if (C4::Context->preference('ElasticsearchMARCSerializationFormat') eq 'MARCXML') {
371
    if ($result->{marc_format} eq 'base64ISO2709') {
372
        return MARC::Record->new_from_usmarc(decode_base64($result->{marc_data}));
373
    }
374
    elsif ($result->{marc_format} eq 'MARCXML') {
372
        return MARC::Record->new_from_xml($result->{marc_data}, 'UTF-8', uc C4::Context->preference('marcflavour'));
375
        return MARC::Record->new_from_xml($result->{marc_data}, 'UTF-8', uc C4::Context->preference('marcflavour'));
373
    }
376
    }
374
    else {
377
    else {
375
        return MARC::Record->new_from_usmarc(decode_base64($result->{marc_data}));
378
        die("Missing marc_format field in Elasticsearch result");
376
    }
379
    }
377
}
380
}
378
381
(-)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 425-435 Administration: Link Here
425
              choices:
425
              choices:
426
                Zebra: Zebra
426
                Zebra: Zebra
427
                Elasticsearch: Elasticsearch
427
                Elasticsearch: Elasticsearch
428
        -
429
            - "Use"
430
            - pref: ElasticsearchMARCSerializationFormat
431
              default: MARCXML
432
              choices:
433
                MARCXML: MARCXML
434
                base64ISO2709: base64ISO2709
435
            - "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."
436
- 

Return to bug 19893