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

(-)a/Koha/SearchEngine/Elasticsearch.pm (-11 / +74 lines)
Lines 80-86 sub get_elasticsearch { Link Here
80
        $self->{elasticsearch} = Search::Elasticsearch->new(
80
        $self->{elasticsearch} = Search::Elasticsearch->new(
81
            client => "5_0::Direct",
81
            client => "5_0::Direct",
82
            nodes => $conf->{nodes},
82
            nodes => $conf->{nodes},
83
            cxn_pool => 'Sniff'
83
            cxn_pool => 'Sniff',
84
            request_timeout => 60
84
        );
85
        );
85
    }
86
    }
86
    return $self->{elasticsearch};
87
    return $self->{elasticsearch};
Lines 348-355 sub marc_records_to_documents { Link Here
348
                }
349
                }
349
            }
350
            }
350
            else {
351
            else {
351
                my $subfields_mappings = $data_fields_rules->{$field->tag()};
352
                my $data_field_rules = $data_fields_rules->{$field->tag()};
352
                if ($subfields_mappings) {
353
354
                if ($data_field_rules) {
355
                    my $subfields_mappings = $data_field_rules->{subfields};
353
                    my $wildcard_mappings = $subfields_mappings->{'*'};
356
                    my $wildcard_mappings = $subfields_mappings->{'*'};
354
                    foreach my $subfield ($field->subfields()) {
357
                    foreach my $subfield ($field->subfields()) {
355
                        my ($code, $data) = @{$subfield};
358
                        my ($code, $data) = @{$subfield};
Lines 361-366 sub marc_records_to_documents { Link Here
361
                            _process_mappings($mappings, $data, $record_document);
364
                            _process_mappings($mappings, $data, $record_document);
362
                        }
365
                        }
363
                    }
366
                    }
367
368
                    my $subfields_join_mappings = $data_field_rules->{subfields_join};
369
                    if ($subfields_join_mappings) {
370
                        foreach my $subfields_group (keys %{$subfields_join_mappings}) {
371
                            # Map each subfield to values, remove empty values, join with space
372
                            my $data = join(
373
                                ' ',
374
                                grep(
375
                                    $_,
376
                                    map { join(' ', $field->subfield($_)) } split(//, $subfields_group)
377
                                )
378
                            );
379
                            if ($data) {
380
                                _process_mappings($subfields_join_mappings->{$subfields_group}, $data, $record_document);
381
                            }
382
                        }
383
                    }
364
                }
384
                }
365
            }
385
            }
366
        }
386
        }
Lines 463-469 sub get_marc_mapping_rules { Link Here
463
        }
483
        }
464
        return @mappings;
484
        return @mappings;
465
    };
485
    };
466
    my $field_spec_regexp = qr/^([0-9]{3})([0-9a-z]+)?(?:_\/(\d+(?:-\d+)?))?$/;
486
    my $field_spec_regexp = qr/^([0-9]{3})([()0-9a-z]+)?(?:_\/(\d+(?:-\d+)?))?$/;
467
    my $leader_regexp = qr/^leader(?:_\/(\d+(?:-\d+)?))?$/;
487
    my $leader_regexp = qr/^leader(?:_\/(\d+(?:-\d+)?))?$/;
468
    my $rules = {
488
    my $rules = {
469
        'leader' => [],
489
        'leader' => [],
Lines 488-506 sub get_marc_mapping_rules { Link Here
488
508
489
        if ($marc_field =~ $field_spec_regexp) {
509
        if ($marc_field =~ $field_spec_regexp) {
490
            my $field_tag = $1;
510
            my $field_tag = $1;
491
            my $subfields = defined $2 ? $2 : '*';
511
512
            my @subfields;
513
            my @subfield_groups;
514
            # Parse and separate subfields form subfield groups
515
            if (defined $2) {
516
                my $subfield_group = '';
517
                my $open_group = 0;
518
519
                foreach my $token (split //, $2) {
520
                    if ($token eq "(") {
521
                        if ($open_group) {
522
                            die("Unmatched opening parenthesis for $marc_field");
523
                        }
524
                        else {
525
                            $open_group = 1;
526
                        }
527
                    }
528
                    elsif ($token eq ")") {
529
                        if ($open_group) {
530
                            if ($subfield_group) {
531
                                push @subfield_groups, $subfield_group;
532
                                $subfield_group = '';
533
                            }
534
                            $open_group = 0;
535
                        }
536
                        else {
537
                            die("Unmatched closing parenthesis for $marc_field");
538
                        }
539
                    }
540
                    elsif ($open_group) {
541
                        $subfield_group .= $token;
542
                    }
543
                    else {
544
                        push @subfields, $token;
545
                    }
546
                }
547
            }
548
            else {
549
                push @subfields, '*';
550
            }
551
492
            my $range = defined $3 ? $3 : undef;
552
            my $range = defined $3 ? $3 : undef;
553
            my @mappings = _field_mappings($facet, $suggestible, $sort, $name, $type, $range);
554
493
            if ($field_tag < 10) {
555
            if ($field_tag < 10) {
494
                $rules->{control_fields}->{$field_tag} //= [];
556
                $rules->{control_fields}->{$field_tag} //= [];
495
                my @mappings = _field_mappings($facet, $suggestible, $sort, $name, $type, $range);
496
                push @{$rules->{control_fields}->{$field_tag}}, @mappings;
557
                push @{$rules->{control_fields}->{$field_tag}}, @mappings;
497
            }
558
            }
498
            else {
559
            else {
499
                $rules->{data_fields}->{$field_tag} //= {};
560
                $rules->{data_fields}->{$field_tag} //= {};
500
                foreach my $subfield (split //, $subfields) {
561
                foreach my $subfield (@subfields) {
501
                    $rules->{data_fields}->{$field_tag}->{$subfield} //= [];
562
                    $rules->{data_fields}->{$field_tag}->{subfields}->{$subfield} //= [];
502
                    my @mappings = _field_mappings($facet, $suggestible, $sort, $name, $type, $range);
563
                    push @{$rules->{data_fields}->{$field_tag}->{subfields}->{$subfield}}, @mappings;
503
                    push @{$rules->{data_fields}->{$field_tag}->{$subfield}}, @mappings;
564
                }
565
                foreach my $subfield_group (@subfield_groups) {
566
                    $rules->{data_fields}->{$field_tag}->{subfields_join}->{$subfield_group} //= [];
567
                    push @{$rules->{data_fields}->{$field_tag}->{subfields_join}->{$subfield_group}}, @mappings;
504
                }
568
                }
505
            }
569
            }
506
        }
570
        }
507
- 

Return to bug 19893