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

(-)a/Koha/SearchEngine/Elasticsearch.pm (+32 lines)
Lines 38-43 use List::Util qw( sum0 reduce ); Link Here
38
use MARC::File::XML;
38
use MARC::File::XML;
39
use MIME::Base64;
39
use MIME::Base64;
40
use Encode qw(encode);
40
use Encode qw(encode);
41
use Business::ISBN;
41
42
42
__PACKAGE__->mk_ro_accessors(qw( index ));
43
__PACKAGE__->mk_ro_accessors(qw( index ));
43
__PACKAGE__->mk_accessors(qw( sort_fields ));
44
__PACKAGE__->mk_accessors(qw( sort_fields ));
Lines 456-461 sub marc_records_to_documents { Link Here
456
                $record_document->{$field} = sum0(grep { !ref($_) && m/\d+(\.\d+)?/} @{$record_document->{$field}});
457
                $record_document->{$field} = sum0(grep { !ref($_) && m/\d+(\.\d+)?/} @{$record_document->{$field}});
457
            }
458
            }
458
        }
459
        }
460
        # Index all applicable ISBN forms (ISBN-10 and ISBN-13 with and without dashes)
461
        foreach my $field (@{$rules->{isbn}}) {
462
            if (defined $record_document->{$field}) {
463
                my @isbns = ();
464
                foreach my $input_isbn (@{$record_document->{$field}}) {
465
                    my $isbn = Business::ISBN->new($input_isbn);
466
                    if (defined $isbn && $isbn->is_valid) {
467
                        my $isbn13 = $isbn->as_isbn13->as_string;
468
                        push @isbns, $isbn13;
469
                        $isbn13 =~ s/\-//g;
470
                        push @isbns, $isbn13;
471
472
                        my $isbn10 = $isbn->as_isbn10;
473
                        if ($isbn10) {
474
                            $isbn10 = $isbn10->as_string;
475
                            push @isbns, $isbn10;
476
                            $isbn10 =~ s/\-//g;
477
                            push @isbns, $isbn10;
478
                        }
479
                    } else {
480
                        push @isbns, $input_isbn;
481
                    }
482
                }
483
                $record_document->{$field} = \@isbns;
484
            }
485
        }
486
459
        # TODO: Perhaps should check if $records_document non empty, but really should never be the case
487
        # TODO: Perhaps should check if $records_document non empty, but really should never be the case
460
        $record->encoding('UTF-8');
488
        $record->encoding('UTF-8');
461
        my @warnings;
489
        my @warnings;
Lines 622-627 sub _get_marc_mapping_rules { Link Here
622
        'control_fields' => {},
650
        'control_fields' => {},
623
        'data_fields' => {},
651
        'data_fields' => {},
624
        'sum' => [],
652
        'sum' => [],
653
        'isbn' => [],
625
        'defaults' => {}
654
        'defaults' => {}
626
    };
655
    };
627
656
Lines 632-637 sub _get_marc_mapping_rules { Link Here
632
        if ($type eq 'sum') {
661
        if ($type eq 'sum') {
633
            push @{$rules->{sum}}, $name;
662
            push @{$rules->{sum}}, $name;
634
        }
663
        }
664
        elsif ($type eq 'isbn') {
665
            push @{$rules->{isbn}}, $name;
666
        }
635
        elsif ($type eq 'boolean') {
667
        elsif ($type eq 'boolean') {
636
            # boolean gets special handling, if value doesn't exist for a field,
668
            # boolean gets special handling, if value doesn't exist for a field,
637
            # it is set to false
669
            # it is set to false
(-)a/t/Koha/SearchEngine/Elasticsearch.t (-3 / +14 lines)
Lines 117-123 subtest 'get_elasticsearch_mappings() tests' => sub { Link Here
117
117
118
subtest 'Koha::SearchEngine::Elasticsearch::marc_records_to_documents () tests' => sub {
118
subtest 'Koha::SearchEngine::Elasticsearch::marc_records_to_documents () tests' => sub {
119
119
120
    plan tests => 45;
120
    plan tests => 32;
121
121
122
    t::lib::Mocks::mock_preference('marcflavour', 'MARC21');
122
    t::lib::Mocks::mock_preference('marcflavour', 'MARC21');
123
123
Lines 131-136 subtest 'Koha::SearchEngine::Elasticsearch::marc_records_to_documents () tests' Link Here
131
            marc_type => 'marc21',
131
            marc_type => 'marc21',
132
            marc_field => '001',
132
            marc_field => '001',
133
        },
133
        },
134
        {
135
            name => 'isbn',
136
            type => 'isbn',
137
            facet => 0,
138
            suggestible => 0,
139
            sort => 0,
140
            marc_type => 'marc21',
141
            marc_field => '020a',
142
        },
134
        {
143
        {
135
            name => 'author',
144
            name => 'author',
136
            type => 'string',
145
            type => 'string',
Lines 246-251 subtest 'Koha::SearchEngine::Elasticsearch::marc_records_to_documents () tests' Link Here
246
    $marc_record_1->leader('     cam  22      a 4500');
255
    $marc_record_1->leader('     cam  22      a 4500');
247
    $marc_record_1->append_fields(
256
    $marc_record_1->append_fields(
248
        MARC::Field->new('001', '123'),
257
        MARC::Field->new('001', '123'),
258
        MARC::Field->new('020', '', '', a => '1-56619-909-3'),
249
        MARC::Field->new('100', '', '', a => 'Author 1'),
259
        MARC::Field->new('100', '', '', a => 'Author 1'),
250
        MARC::Field->new('110', '', '', a => 'Corp Author'),
260
        MARC::Field->new('110', '', '', a => 'Corp Author'),
251
        MARC::Field->new('210', '', '', a => 'Title 1'),
261
        MARC::Field->new('210', '', '', a => 'Title 1'),
Lines 271-277 subtest 'Koha::SearchEngine::Elasticsearch::marc_records_to_documents () tests' Link Here
271
    my $docs = $see->marc_records_to_documents($records);
281
    my $docs = $see->marc_records_to_documents($records);
272
282
273
    # First record:
283
    # First record:
274
275
    is(scalar @{$docs}, 2, 'Two records converted to documents');
284
    is(scalar @{$docs}, 2, 'Two records converted to documents');
276
285
277
    is($docs->[0][0], '1234567', 'First document biblionumber should be set as first element in document touple');
286
    is($docs->[0][0], '1234567', 'First document biblionumber should be set as first element in document touple');
Lines 360-365 subtest 'Koha::SearchEngine::Elasticsearch::marc_records_to_documents () tests' Link Here
360
        'First document type_of_record_and_bib_level field should be set correctly'
369
        'First document type_of_record_and_bib_level field should be set correctly'
361
    );
370
    );
362
371
372
    is(scalar @{$docs->[0][1]->{isbn}}, 4, 'First document isbn field should contain four values');
373
    is_deeply($docs->[0][1]->{isbn}, ['978-1-56619-909-4', '9781566199094', '1-56619-909-3', '1566199093'], 'First document isbn field should be set correctly');
374
363
    # Second record:
375
    # Second record:
364
376
365
    is(scalar @{$docs->[1][1]->{author}}, 1, 'Second document author field should contain one value');
377
    is(scalar @{$docs->[1][1]->{author}}, 1, 'Second document author field should contain one value');
366
- 

Return to bug 20244