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

(-)a/Koha/SearchEngine/Elasticsearch.pm (-15 / +14 lines)
Lines 373-387 sub marc_records_to_documents { Link Here
373
                }
373
                }
374
                my $subfields_mappings = $data_fields_rules->{$tag};
374
                my $subfields_mappings = $data_fields_rules->{$tag};
375
                if ($subfields_mappings) {
375
                if ($subfields_mappings) {
376
                    my $wildcard_mappings = $subfields_mappings->{'*'};
376
                    foreach my $rule (@{$subfields_mappings}) {
377
                    foreach my $subfield ($field->subfields()) {
377
                        my @selected = ();
378
                        my ($code, $data) = @{$subfield};
378
                        foreach my $subfield ($field->subfields()) {
379
                        my $mappings = $subfields_mappings->{$code} // [];
379
                            my ($code, $data) = @{$subfield};
380
                        if ($wildcard_mappings) {
380
                            if (!%{$rule->{codes}} || defined $rule->{codes}{$code}) {
381
                            $mappings = [@{$mappings}, @{$wildcard_mappings}];
381
                                $data =~ s/\s+$//;
382
                                push @selected, $data;
383
                            }
382
                        }
384
                        }
383
                        if (@{$mappings}) {
385
                        if (@selected) {
384
                            _process_mappings($mappings, $data, $record_document);
386
                            _process_mappings($rule->{mappings}, join(' ', @selected), $record_document, $altscript);
385
                        }
387
                        }
386
                    }
388
                    }
387
                }
389
                }
Lines 542-548 sub get_marc_mapping_rules { Link Here
542
544
543
        if ($marc_field =~ $field_spec_regexp) {
545
        if ($marc_field =~ $field_spec_regexp) {
544
            my $field_tag = $1;
546
            my $field_tag = $1;
545
            my $subfields = defined $2 ? $2 : '*';
547
            my %subfields = defined $2 ? map { $_ => 1 } split(//, $2) : ();
546
            my $range = defined $3 ? $3 : undef;
548
            my $range = defined $3 ? $3 : undef;
547
            if ($field_tag < 10) {
549
            if ($field_tag < 10) {
548
                $rules->{control_fields}->{$field_tag} //= [];
550
                $rules->{control_fields}->{$field_tag} //= [];
Lines 550-561 sub get_marc_mapping_rules { Link Here
550
                push @{$rules->{control_fields}->{$field_tag}}, @mappings;
552
                push @{$rules->{control_fields}->{$field_tag}}, @mappings;
551
            }
553
            }
552
            else {
554
            else {
553
                $rules->{data_fields}->{$field_tag} //= {};
555
                my @mappings = _field_mappings($facet, $suggestible, $sort, $name, $type, $range);
554
                foreach my $subfield (split //, $subfields) {
556
                $rules->{data_fields}->{$field_tag} //= [];
555
                    $rules->{data_fields}->{$field_tag}->{$subfield} //= [];
557
                push @{$rules->{data_fields}->{$field_tag}}, {codes => \%subfields, mappings => \@mappings};
556
                    my @mappings = _field_mappings($facet, $suggestible, $sort, $name, $type, $range);
557
                    push @{$rules->{data_fields}->{$field_tag}->{$subfield}}, @mappings;
558
                }
559
            }
558
            }
560
        }
559
        }
561
        elsif ($marc_field =~ $leader_regexp) {
560
        elsif ($marc_field =~ $leader_regexp) {
(-)a/admin/searchengine/elasticsearch/mappings.yaml (-1 / +1 lines)
Lines 2939-2945 biblios: Link Here
2939
        sort: ~
2939
        sort: ~
2940
        suggestible: ''
2940
        suggestible: ''
2941
      - facet: ''
2941
      - facet: ''
2942
        marc_field: 245a
2942
        marc_field: 245ab
2943
        marc_type: marc21
2943
        marc_type: marc21
2944
        sort: 1
2944
        sort: 1
2945
        suggestible: '1'
2945
        suggestible: '1'
(-)a/t/Koha/SearchEngine/Elasticsearch.t (-5 / +5 lines)
Lines 154-160 subtest 'Koha::SearchEngine::Elasticsearch::marc_records_to_documents () tests' Link Here
154
            suggestible => 1,
154
            suggestible => 1,
155
            sort => 1,
155
            sort => 1,
156
            marc_type => 'marc21',
156
            marc_type => 'marc21',
157
            marc_field => '245a',
157
            marc_field => '245ab',
158
        },
158
        },
159
        {
159
        {
160
            name => 'unimarc_title',
160
            name => 'unimarc_title',
Lines 238-244 subtest 'Koha::SearchEngine::Elasticsearch::marc_records_to_documents () tests' Link Here
238
        MARC::Field->new('100', '', '', a => 'Author 1'),
238
        MARC::Field->new('100', '', '', a => 'Author 1'),
239
        MARC::Field->new('110', '', '', a => 'Corp Author'),
239
        MARC::Field->new('110', '', '', a => 'Corp Author'),
240
        MARC::Field->new('210', '', '', a => 'Title 1'),
240
        MARC::Field->new('210', '', '', a => 'Title 1'),
241
        MARC::Field->new('245', '', '', a => 'Title: first record'),
241
        MARC::Field->new('245', '', '', a => 'Title: first record : ', b => 'Subtitle', 'c' => 'Author'),
242
        MARC::Field->new('246', '', '', a => 'Another title : first record : ', b => 'Subtitle'),
242
        MARC::Field->new('999', '', '', c => '1234567'),
243
        MARC::Field->new('999', '', '', c => '1234567'),
243
        # '  ' for testing trimming of white space in boolean value callback:
244
        # '  ' for testing trimming of white space in boolean value callback:
244
        MARC::Field->new('952', '', '', 0 => '  ', g => '123.30'),
245
        MARC::Field->new('952', '', '', 0 => '  ', g => '123.30'),
Lines 271-277 subtest 'Koha::SearchEngine::Elasticsearch::marc_records_to_documents () tests' Link Here
271
    is_deeply($docs->[0][1]->{author__sort}, ['Author 1 Corp Author'], 'First document author__sort field should be set correctly');
272
    is_deeply($docs->[0][1]->{author__sort}, ['Author 1 Corp Author'], 'First document author__sort field should be set correctly');
272
273
273
    is(scalar @{$docs->[0][1]->{title__sort}}, 1, 'First document title__sort field should have one value');
274
    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');
275
    is_deeply($docs->[0][1]->{title__sort}, ['Title: first record : Subtitle'], 'First document title__sort field should be set correctly');
275
276
276
    is(scalar @{$docs->[0][1]->{author__suggestion}}, 2, 'First document author__suggestion field should contain two values');
277
    is(scalar @{$docs->[0][1]->{author__suggestion}}, 2, 'First document author__suggestion field should contain two values');
277
    is_deeply(
278
    is_deeply(
Lines 290-296 subtest 'Koha::SearchEngine::Elasticsearch::marc_records_to_documents () tests' Link Here
290
    is(scalar @{$docs->[0][1]->{title__suggestion}}, 1, 'First document title__suggestion field should contain one value');
291
    is(scalar @{$docs->[0][1]->{title__suggestion}}, 1, 'First document title__suggestion field should contain one value');
291
    is_deeply(
292
    is_deeply(
292
        $docs->[0][1]->{title__suggestion},
293
        $docs->[0][1]->{title__suggestion},
293
        [{ 'input' => 'Title: first record' }],
294
        [{ 'input' => 'Title: first record : Subtitle' }],
294
        'First document title__suggestion field should be set correctly'
295
        'First document title__suggestion field should be set correctly'
295
    );
296
    );
296
297
297
- 

Return to bug 20244