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

(-)a/Koha/SearchEngine/Elasticsearch.pm (+18 lines)
Lines 557-562 sub marc_records_to_documents { Link Here
557
                $record_document->{$field} = \@isbns;
557
                $record_document->{$field} = \@isbns;
558
            }
558
            }
559
        }
559
        }
560
        foreach my $field (@{$rules->{year}}) {
561
            if (defined $record_document->{$field}) {
562
                my @years = ();
563
                foreach my $input_year (@{$record_document->{$field}}) {
564
                    my @field_years = ( $input_year =~ /[0-9ux]{4}/g );
565
                    foreach my $year (@field_years){
566
                        $year =~ s/[ux]/0/g;
567
                        push @years, $year;
568
                    }
569
                }
570
                $record_document->{$field} = \@years;
571
            }
572
        }
560
573
561
        # Remove duplicate values and collapse sort fields
574
        # Remove duplicate values and collapse sort fields
562
        foreach my $field (keys %{$record_document}) {
575
        foreach my $field (keys %{$record_document}) {
Lines 839-844 sub _get_marc_mapping_rules { Link Here
839
        'data_fields' => {},
852
        'data_fields' => {},
840
        'sum' => [],
853
        'sum' => [],
841
        'isbn' => [],
854
        'isbn' => [],
855
        'year' => [],
842
        'defaults' => {}
856
        'defaults' => {}
843
    };
857
    };
844
858
Lines 853-858 sub _get_marc_mapping_rules { Link Here
853
        elsif ($type eq 'isbn') {
867
        elsif ($type eq 'isbn') {
854
            push @{$rules->{isbn}}, $name;
868
            push @{$rules->{isbn}}, $name;
855
        }
869
        }
870
        elsif ($type eq 'year') {
871
            push @{$rules->{year}}, $name;
872
            push @{$rules->{year}}, $name."__sort" if $sort;
873
        }
856
        elsif ($type eq 'boolean') {
874
        elsif ($type eq 'boolean') {
857
            # boolean gets special handling, if value doesn't exist for a field,
875
            # boolean gets special handling, if value doesn't exist for a field,
858
            # it is set to false
876
            # it is set to false
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/searchengine/elasticsearch/mappings.tt (+5 lines)
Lines 192-197 a.add, a.delete { Link Here
192
                          [% ELSE %]
192
                          [% ELSE %]
193
                            <option value="date">Date</option>
193
                            <option value="date">Date</option>
194
                          [% END %]
194
                          [% END %]
195
                          [% IF search_field.type == "year" %]
196
                            <option value="year" selected="selected">Year</option>
197
                          [% ELSE %]
198
                            <option value="year">Year</option>
199
                          [% END %]
195
                          [% IF search_field.type == "number" %]
200
                          [% IF search_field.type == "number" %]
196
                            <option value="number" selected="selected">Number</option>
201
                            <option value="number" selected="selected">Number</option>
197
                          [% ELSE %]
202
                          [% ELSE %]
(-)a/t/Koha/SearchEngine/Elasticsearch.t (-2 / +50 lines)
Lines 118-124 subtest 'get_elasticsearch_mappings() tests' => sub { Link Here
118
118
119
subtest 'Koha::SearchEngine::Elasticsearch::marc_records_to_documents () tests' => sub {
119
subtest 'Koha::SearchEngine::Elasticsearch::marc_records_to_documents () tests' => sub {
120
120
121
    plan tests => 51;
121
    plan tests => 55;
122
122
123
    t::lib::Mocks::mock_preference('marcflavour', 'MARC21');
123
    t::lib::Mocks::mock_preference('marcflavour', 'MARC21');
124
    t::lib::Mocks::mock_preference('ElasticsearchMARCFormat', 'ISO2709');
124
    t::lib::Mocks::mock_preference('ElasticsearchMARCFormat', 'ISO2709');
Lines 274-279 subtest 'Koha::SearchEngine::Elasticsearch::marc_records_to_documents () tests' Link Here
274
            marc_type => 'marc21',
274
            marc_type => 'marc21',
275
            marc_field => '952l',
275
            marc_field => '952l',
276
        },
276
        },
277
        {
278
            name => 'copydate',
279
            type => 'year',
280
            facet => 0,
281
            suggestible => 0,
282
            searchable => 1,
283
            sort => 1,
284
            marc_type => 'marc21',
285
            marc_field => '260c',
286
        },
287
        {
288
            name => 'date-of-publication',
289
            type => 'year',
290
            facet => 0,
291
            suggestible => 0,
292
            searchable => 1,
293
            sort => 1,
294
            marc_type => 'marc21',
295
            marc_field => '008_/7-10',
296
        },
277
    );
297
    );
278
298
279
    my $se = Test::MockModule->new('Koha::SearchEngine::Elasticsearch');
299
    my $se = Test::MockModule->new('Koha::SearchEngine::Elasticsearch');
Lines 305-315 subtest 'Koha::SearchEngine::Elasticsearch::marc_records_to_documents () tests' Link Here
305
    $marc_record_1->append_fields(
325
    $marc_record_1->append_fields(
306
        MARC::Field->new('001', '123'),
326
        MARC::Field->new('001', '123'),
307
        MARC::Field->new('007', 'ku'),
327
        MARC::Field->new('007', 'ku'),
328
        MARC::Field->new('008', '980514s19uu    gw            000 0 lat  '),
308
        MARC::Field->new('020', '', '', a => '1-56619-909-3'),
329
        MARC::Field->new('020', '', '', a => '1-56619-909-3'),
309
        MARC::Field->new('100', '', '', a => 'Author 1'),
330
        MARC::Field->new('100', '', '', a => 'Author 1'),
310
        MARC::Field->new('110', '', '', a => 'Corp Author'),
331
        MARC::Field->new('110', '', '', a => 'Corp Author'),
311
        MARC::Field->new('210', '', '', a => 'Title 1'),
332
        MARC::Field->new('210', '', '', a => 'Title 1'),
312
        MARC::Field->new('245', '', '', a => 'Title:', b => 'first record'),
333
        MARC::Field->new('245', '', '', a => 'Title:', b => 'first record'),
334
        MARC::Field->new('260', '', '', a => 'New York :', b => 'Ace ,', 'c' => 'c1962'),
313
        MARC::Field->new('999', '', '', c => '1234567'),
335
        MARC::Field->new('999', '', '', c => '1234567'),
314
        # '  ' for testing trimming of white space in boolean value callback:
336
        # '  ' for testing trimming of white space in boolean value callback:
315
        MARC::Field->new('952', '', '', 0 => '  ', g => '123.30', o => $callno, l => 3),
337
        MARC::Field->new('952', '', '', 0 => '  ', g => '123.30', o => $callno, l => 3),
Lines 319-327 subtest 'Koha::SearchEngine::Elasticsearch::marc_records_to_documents () tests' Link Here
319
    my $marc_record_2 = MARC::Record->new();
341
    my $marc_record_2 = MARC::Record->new();
320
    $marc_record_2->leader('     cam  22      a 4500');
342
    $marc_record_2->leader('     cam  22      a 4500');
321
    $marc_record_2->append_fields(
343
    $marc_record_2->append_fields(
344
        MARC::Field->new('008', '980514s195u    gw            000 0 lat  '),
322
        MARC::Field->new('100', '', '', a => 'Author 2'),
345
        MARC::Field->new('100', '', '', a => 'Author 2'),
323
        # MARC::Field->new('210', '', '', a => 'Title 2'),
346
        # MARC::Field->new('210', '', '', a => 'Title 2'),
324
        # MARC::Field->new('245', '', '', a => 'Title: second record'),
347
        # MARC::Field->new('245', '', '', a => 'Title: second record'),
348
        MARC::Field->new('260', '', '', a => 'New York :', b => 'Ace ,', 'c' => '1963-2003'),
325
        MARC::Field->new('999', '', '', c => '1234568'),
349
        MARC::Field->new('999', '', '', c => '1234568'),
326
        MARC::Field->new('952', '', '', 0 => 1, g => 'string where should be numeric', o => $long_callno),
350
        MARC::Field->new('952', '', '', 0 => 1, g => 'string where should be numeric', o => $long_callno),
327
    );
351
    );
Lines 433-438 subtest 'Koha::SearchEngine::Elasticsearch::marc_records_to_documents () tests' Link Here
433
        'First document local_classification field should be set correctly'
457
        'First document local_classification field should be set correctly'
434
    );
458
    );
435
459
460
    # Test year type
461
    is_deeply(
462
        $docs->[0]->{'copydate'},
463
        ['1962'],
464
        'First document copydate field should be set correctly'
465
    );
466
    is_deeply(
467
        $docs->[0]->{'date-of-publication'},
468
        ['1900'],
469
        'First document date-of-publication field should be set correctly'
470
    );
471
436
    # Second record:
472
    # Second record:
437
473
438
    is(scalar @{$docs->[1]->{author}}, 1, 'Second document author field should contain one value');
474
    is(scalar @{$docs->[1]->{author}}, 1, 'Second document author field should contain one value');
Lines 457-462 subtest 'Koha::SearchEngine::Elasticsearch::marc_records_to_documents () tests' Link Here
457
        'Second document local_classification__sort field should be set correctly'
493
        'Second document local_classification__sort field should be set correctly'
458
    );
494
    );
459
495
496
    # Test year type
497
    is_deeply(
498
        $docs->[1]->{'copydate'},
499
        ['1963','2003'],
500
        'Second document copydate field should be set correctly'
501
    );
502
    is_deeply(
503
        $docs->[1]->{'date-of-publication'},
504
        ['1950'],
505
        'Second document date-of-publication field should be set correctly'
506
    );
507
508
460
    # Mappings marc_type:
509
    # Mappings marc_type:
461
510
462
    ok(!(defined $docs->[0]->{unimarc_title}), "No mapping when marc_type doesn't match marc flavour");
511
    ok(!(defined $docs->[0]->{unimarc_title}), "No mapping when marc_type doesn't match marc flavour");
463
- 

Return to bug 24559