Lines 132-138
subtest 'get_elasticsearch_mappings() tests' => sub {
Link Here
|
132 |
|
132 |
|
133 |
subtest 'Koha::SearchEngine::Elasticsearch::marc_records_to_documents () tests' => sub { |
133 |
subtest 'Koha::SearchEngine::Elasticsearch::marc_records_to_documents () tests' => sub { |
134 |
|
134 |
|
135 |
plan tests => 53; |
135 |
plan tests => 59; |
136 |
|
136 |
|
137 |
t::lib::Mocks::mock_preference('marcflavour', 'MARC21'); |
137 |
t::lib::Mocks::mock_preference('marcflavour', 'MARC21'); |
138 |
t::lib::Mocks::mock_preference('ElasticsearchMARCFormat', 'ISO2709'); |
138 |
t::lib::Mocks::mock_preference('ElasticsearchMARCFormat', 'ISO2709'); |
Lines 297-303
subtest 'Koha::SearchEngine::Elasticsearch::marc_records_to_documents () tests'
Link Here
|
297 |
sort => 1, |
297 |
sort => 1, |
298 |
marc_type => 'marc21', |
298 |
marc_type => 'marc21', |
299 |
marc_field => '952l', |
299 |
marc_field => '952l', |
|
|
300 |
}, |
301 |
{ |
302 |
name => 'copydate', |
303 |
type => 'year', |
304 |
facet => 0, |
305 |
suggestible => 0, |
306 |
searchable => 1, |
307 |
sort => 1, |
308 |
marc_type => 'marc21', |
309 |
marc_field => '260c', |
310 |
}, |
311 |
{ |
312 |
name => 'date-of-publication', |
313 |
type => 'year', |
314 |
facet => 0, |
315 |
suggestible => 0, |
316 |
searchable => 1, |
317 |
sort => 1, |
318 |
marc_type => 'marc21', |
319 |
marc_field => '008_/7-10', |
300 |
}, |
320 |
}, |
|
|
321 |
|
301 |
); |
322 |
); |
302 |
|
323 |
|
303 |
my $se = Test::MockModule->new('Koha::SearchEngine::Elasticsearch'); |
324 |
my $se = Test::MockModule->new('Koha::SearchEngine::Elasticsearch'); |
Lines 329-340
subtest 'Koha::SearchEngine::Elasticsearch::marc_records_to_documents () tests'
Link Here
|
329 |
$marc_record_1->append_fields( |
350 |
$marc_record_1->append_fields( |
330 |
MARC::Field->new('001', '123'), |
351 |
MARC::Field->new('001', '123'), |
331 |
MARC::Field->new('007', 'ku'), |
352 |
MARC::Field->new('007', 'ku'), |
|
|
353 |
MARC::Field->new('008', '901111s1962 xxk|||| |00| ||eng c'), |
332 |
MARC::Field->new('020', '', '', a => '1-56619-909-3'), |
354 |
MARC::Field->new('020', '', '', a => '1-56619-909-3'), |
333 |
MARC::Field->new('100', '', '', a => 'Author 1'), |
355 |
MARC::Field->new('100', '', '', a => 'Author 1'), |
334 |
MARC::Field->new('110', '', '', a => 'Corp Author'), |
356 |
MARC::Field->new('110', '', '', a => 'Corp Author'), |
335 |
MARC::Field->new('210', '', '', a => 'Title 1'), |
357 |
MARC::Field->new('210', '', '', a => 'Title 1'), |
336 |
MARC::Field->new('240', '', '4', a => 'The uniform title with nonfiling indicator'), |
358 |
MARC::Field->new('240', '', '4', a => 'The uniform title with nonfiling indicator'), |
337 |
MARC::Field->new('245', '', '', a => 'Title:', b => 'first record'), |
359 |
MARC::Field->new('245', '', '', a => 'Title:', b => 'first record'), |
|
|
360 |
MARC::Field->new('260', '', '', a => 'New York :', b => 'Ace ,', c => 'c1962'), |
338 |
MARC::Field->new('999', '', '', c => '1234567'), |
361 |
MARC::Field->new('999', '', '', c => '1234567'), |
339 |
# ' ' for testing trimming of white space in boolean value callback: |
362 |
# ' ' for testing trimming of white space in boolean value callback: |
340 |
MARC::Field->new('952', '', '', 0 => ' ', g => '123.30', o => $callno, l => 3), |
363 |
MARC::Field->new('952', '', '', 0 => ' ', g => '123.30', o => $callno, l => 3), |
Lines 344-363
subtest 'Koha::SearchEngine::Elasticsearch::marc_records_to_documents () tests'
Link Here
|
344 |
my $marc_record_2 = MARC::Record->new(); |
367 |
my $marc_record_2 = MARC::Record->new(); |
345 |
$marc_record_2->leader(' cam 22 a 4500'); |
368 |
$marc_record_2->leader(' cam 22 a 4500'); |
346 |
$marc_record_2->append_fields( |
369 |
$marc_record_2->append_fields( |
|
|
370 |
MARC::Field->new('008', '901111s19uu xxk|||| |00| ||eng c'), |
347 |
MARC::Field->new('100', '', '', a => 'Author 2'), |
371 |
MARC::Field->new('100', '', '', a => 'Author 2'), |
348 |
# MARC::Field->new('210', '', '', a => 'Title 2'), |
372 |
# MARC::Field->new('210', '', '', a => 'Title 2'), |
349 |
# MARC::Field->new('245', '', '', a => 'Title: second record'), |
373 |
# MARC::Field->new('245', '', '', a => 'Title: second record'), |
|
|
374 |
MARC::Field->new('260', '', '', a => 'New York :', b => 'Ace ,', c => '1963-2003'), |
350 |
MARC::Field->new('999', '', '', c => '1234568'), |
375 |
MARC::Field->new('999', '', '', c => '1234568'), |
351 |
MARC::Field->new('952', '', '', 0 => 1, g => 'string where should be numeric', o => $long_callno), |
376 |
MARC::Field->new('952', '', '', 0 => 1, g => 'string where should be numeric', o => $long_callno), |
352 |
); |
377 |
); |
353 |
my $records = [ $marc_record_1, $marc_record_2 ]; |
378 |
|
|
|
379 |
my $marc_record_3 = MARC::Record->new(); |
380 |
$marc_record_3->leader(' cam 22 a 4500'); |
381 |
$marc_record_3->append_fields( |
382 |
MARC::Field->new('008', '901111s19uu xxk|||| |00| ||eng c'), |
383 |
MARC::Field->new('100', '', '', a => 'Author 2'), |
384 |
# MARC::Field->new('210', '', '', a => 'Title 3'), |
385 |
# MARC::Field->new('245', '', '', a => 'Title: third record'), |
386 |
MARC::Field->new('260', '', '', a => 'New York :', b => 'Ace ,', c => ' 89 '), |
387 |
MARC::Field->new('999', '', '', c => '1234568'), |
388 |
MARC::Field->new('952', '', '', 0 => 1, g => 'string where should be numeric', o => $long_callno), |
389 |
); |
390 |
my $records = [$marc_record_1, $marc_record_2, $marc_record_3]; |
354 |
|
391 |
|
355 |
$see->get_elasticsearch_mappings(); #sort_fields will call this and use the actual db values unless we call it first |
392 |
$see->get_elasticsearch_mappings(); #sort_fields will call this and use the actual db values unless we call it first |
356 |
|
393 |
|
357 |
my $docs = $see->marc_records_to_documents($records); |
394 |
my $docs = $see->marc_records_to_documents($records); |
358 |
|
395 |
|
359 |
# First record: |
396 |
# First record: |
360 |
is(scalar @{$docs}, 2, 'Two records converted to documents'); |
397 |
is(scalar @{$docs}, 3, 'Two records converted to documents'); |
361 |
|
398 |
|
362 |
is_deeply($docs->[0]->{control_number}, ['123'], 'First record control number should be set correctly'); |
399 |
is_deeply($docs->[0]->{control_number}, ['123'], 'First record control number should be set correctly'); |
363 |
|
400 |
|
Lines 470-475
subtest 'Koha::SearchEngine::Elasticsearch::marc_records_to_documents () tests'
Link Here
|
470 |
'First document uniform_title__sort field should contain the title with the first four initial characters removed' |
507 |
'First document uniform_title__sort field should contain the title with the first four initial characters removed' |
471 |
); |
508 |
); |
472 |
|
509 |
|
|
|
510 |
# Tests for 'year' type |
511 |
is(scalar @{$docs->[0]->{'date-of-publication'}}, 1, 'First document date-of-publication field should contain one value'); |
512 |
is_deeply($docs->[0]->{'date-of-publication'}, ['1962'], 'First document date-of-publication field should be set correctly'); |
513 |
|
514 |
is_deeply( |
515 |
$docs->[0]->{'copydate'}, |
516 |
['1962'], |
517 |
'First document copydate field should be set correctly' |
518 |
); |
519 |
|
473 |
# Second record: |
520 |
# Second record: |
474 |
|
521 |
|
475 |
is(scalar @{$docs->[1]->{author}}, 1, 'Second document author field should contain one value'); |
522 |
is(scalar @{$docs->[1]->{author}}, 1, 'Second document author field should contain one value'); |
Lines 494-499
subtest 'Koha::SearchEngine::Elasticsearch::marc_records_to_documents () tests'
Link Here
|
494 |
'Second document local_classification__sort field should be set correctly' |
541 |
'Second document local_classification__sort field should be set correctly' |
495 |
); |
542 |
); |
496 |
|
543 |
|
|
|
544 |
# Tests for 'year' type |
545 |
is_deeply( |
546 |
$docs->[1]->{'copydate'}, |
547 |
['1963', '2003'], |
548 |
'Second document copydate field should be set correctly' |
549 |
); |
550 |
is_deeply( |
551 |
$docs->[1]->{'date-of-publication'}, |
552 |
['1900'], |
553 |
'Second document date-of-publication field should be set correctly' |
554 |
); |
555 |
|
556 |
# Third record: |
557 |
|
558 |
is_deeply( |
559 |
$docs->[2]->{'copydate'}, |
560 |
['0890'], |
561 |
'Third document copydate field should be set correctly' |
562 |
); |
563 |
|
497 |
# Mappings marc_type: |
564 |
# Mappings marc_type: |
498 |
|
565 |
|
499 |
ok(!(defined $docs->[0]->{unimarc_title}), "No mapping when marc_type doesn't match marc flavour"); |
566 |
ok(!(defined $docs->[0]->{unimarc_title}), "No mapping when marc_type doesn't match marc flavour"); |