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

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

Return to bug 20244