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

(-)a/Koha/SearchEngine/Elasticsearch.pm (-8 / +30 lines)
Lines 312-318 sub marc_records_to_documents { Link Here
312
    my @record_documents;
312
    my @record_documents;
313
313
314
    sub _process_mappings {
314
    sub _process_mappings {
315
        my ($mappings, $data, $record_document) = @_;
315
        my ($mappings, $data, $record_document, $altscript) = @_;
316
        foreach my $mapping (@{$mappings}) {
316
        foreach my $mapping (@{$mappings}) {
317
            my ($target, $options) = @{$mapping};
317
            my ($target, $options) = @{$mapping};
318
            # Copy (scalar) data since can have multiple targets
318
            # Copy (scalar) data since can have multiple targets
Lines 332-355 sub marc_records_to_documents { Link Here
332
                    $options->{property} => $_data
332
                    $options->{property} => $_data
333
                }
333
                }
334
            }
334
            }
335
            push @{$record_document->{$target}}, $_data;
335
336
            # For sort fields, index only a single field with concatenated values
337
            # and ignore alt script fields
338
            if ($target =~ /__sort$/) {
339
                if (!$altscript) {
340
                    if (!@{$record_document->{$target}}) {
341
                        push @{$record_document->{$target}}, $_data;
342
                    } else {
343
                        @{$record_document->{$target}}[0] .= " $_data";
344
                    }
345
                }
346
            } else {
347
                push @{$record_document->{$target}}, $_data;
348
            }
336
        }
349
        }
337
    }
350
    }
338
    foreach my $record (@{$records}) {
351
    foreach my $record (@{$records}) {
339
        my $record_document = {};
352
        my $record_document = {};
340
        my $mappings = $rules->{leader};
353
        my $mappings = $rules->{leader};
341
        if ($mappings) {
354
        if ($mappings) {
342
            _process_mappings($mappings, $record->leader(), $record_document);
355
            _process_mappings($mappings, $record->leader(), $record_document, 0);
343
        }
356
        }
344
        foreach my $field ($record->fields()) {
357
        foreach my $field ($record->fields()) {
345
            if($field->is_control_field()) {
358
            if ($field->is_control_field()) {
346
                my $mappings = $control_fields_rules->{$field->tag()};
359
                my $mappings = $control_fields_rules->{$field->tag()};
347
                if ($mappings) {
360
                if ($mappings) {
348
                    _process_mappings($mappings, $field->data(), $record_document);
361
                    _process_mappings($mappings, $field->data(), $record_document, 0);
349
                }
362
                }
350
            }
363
            } else {
351
            else {
364
                my $tag = $field->tag();
352
                my $subfields_mappings = $data_fields_rules->{$field->tag()};
365
                # Handle alternate scripts in MARC 21
366
                my $altscript = 0;
367
                if ($marcflavour eq 'marc21' && $tag eq '880') {
368
                    my $sub6 = $field->subfield('6');
369
                    if ($sub6 =~ /^(...)-\d+/) {
370
                        $tag = $1;
371
                        $altscript = 1;
372
                    }
373
                }
374
                my $subfields_mappings = $data_fields_rules->{$tag};
353
                if ($subfields_mappings) {
375
                if ($subfields_mappings) {
354
                    my $wildcard_mappings = $subfields_mappings->{'*'};
376
                    my $wildcard_mappings = $subfields_mappings->{'*'};
355
                    foreach my $subfield ($field->subfields()) {
377
                    foreach my $subfield ($field->subfields()) {
(-)a/t/Koha/SearchEngine/Elasticsearch.t (-3 / +2 lines)
Lines 267-274 subtest 'Koha::SearchEngine::Elasticsearch::marc_records_to_documents () tests' Link Here
267
    is(scalar @{$docs->[0][1]->{author}}, 2, 'First document author field should contain two values');
267
    is(scalar @{$docs->[0][1]->{author}}, 2, 'First document author field should contain two values');
268
    is_deeply($docs->[0][1]->{author}, ['Author 1', 'Corp Author'], 'First document author field should be set correctly');
268
    is_deeply($docs->[0][1]->{author}, ['Author 1', 'Corp Author'], 'First document author field should be set correctly');
269
269
270
    is(scalar @{$docs->[0][1]->{author__sort}}, 2, 'First document author__sort field should have two values');
270
    is(scalar @{$docs->[0][1]->{author__sort}}, 1, 'First document author__sort field should have a single value');
271
    is_deeply($docs->[0][1]->{author__sort}, ['Author 1', 'Corp Author'], 'First document author__sort field should be set correctly');
271
    is_deeply($docs->[0][1]->{author__sort}, ['Author 1 Corp Author'], 'First document author__sort field should be set correctly');
272
272
273
    is(scalar @{$docs->[0][1]->{title__sort}}, 1, 'First document title__sort field should have one value');
273
    is(scalar @{$docs->[0][1]->{title__sort}}, 1, 'First document title__sort field should have one value');
274
    is_deeply($docs->[0][1]->{title__sort}, ['Title: first record'], 'First document title__sort field should be set correctly');
274
    is_deeply($docs->[0][1]->{title__sort}, ['Title: first record'], 'First document title__sort field should be set correctly');
275
- 

Return to bug 20244