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 => 50; |
120 |
plan tests => 49; |
121 |
|
121 |
|
122 |
t::lib::Mocks::mock_preference('marcflavour', 'MARC21'); |
122 |
t::lib::Mocks::mock_preference('marcflavour', 'MARC21'); |
123 |
t::lib::Mocks::mock_preference('ElasticsearchMARCFormat', 'ISO2709'); |
123 |
t::lib::Mocks::mock_preference('ElasticsearchMARCFormat', 'ISO2709'); |
Lines 322-348
subtest 'Koha::SearchEngine::Elasticsearch::marc_records_to_documents () tests'
Link Here
|
322 |
|
322 |
|
323 |
# First record: |
323 |
# First record: |
324 |
is(scalar @{$docs}, 2, 'Two records converted to documents'); |
324 |
is(scalar @{$docs}, 2, 'Two records converted to documents'); |
325 |
is($docs->[0][0], '1234567', 'First document biblionumber should be set as first element in document touple'); |
|
|
326 |
|
325 |
|
327 |
is_deeply($docs->[0][1]->{control_number}, ['123'], 'First record control number should be set correctly'); |
326 |
is_deeply($docs->[0]->{control_number}, ['123'], 'First record control number should be set correctly'); |
328 |
|
327 |
|
329 |
is_deeply($docs->[0][1]->{'ff7-00'}, ['k'], 'First record ff7-00 should be set correctly'); |
328 |
is_deeply($docs->[0]->{'ff7-00'}, ['k'], 'First record ff7-00 should be set correctly'); |
330 |
|
329 |
|
331 |
is(scalar @{$docs->[0][1]->{author}}, 2, 'First document author field should contain two values'); |
330 |
is(scalar @{$docs->[0]->{author}}, 2, 'First document author field should contain two values'); |
332 |
is_deeply($docs->[0][1]->{author}, ['Author 1', 'Corp Author'], 'First document author field should be set correctly'); |
331 |
is_deeply($docs->[0]->{author}, ['Author 1', 'Corp Author'], 'First document author field should be set correctly'); |
333 |
|
332 |
|
334 |
is(scalar @{$docs->[0][1]->{author__sort}}, 1, 'First document author__sort field should have a single value'); |
333 |
is(scalar @{$docs->[0]->{author__sort}}, 1, 'First document author__sort field should have a single value'); |
335 |
is_deeply($docs->[0][1]->{author__sort}, ['Author 1 Corp Author'], 'First document author__sort field should be set correctly'); |
334 |
is_deeply($docs->[0]->{author__sort}, ['Author 1 Corp Author'], 'First document author__sort field should be set correctly'); |
336 |
|
335 |
|
337 |
is(scalar @{$docs->[0][1]->{title__sort}}, 1, 'First document title__sort field should have a single'); |
336 |
is(scalar @{$docs->[0]->{title__sort}}, 1, 'First document title__sort field should have a single'); |
338 |
is_deeply($docs->[0][1]->{title__sort}, ['Title: first record Title: first record'], 'First document title__sort field should be set correctly'); |
337 |
is_deeply($docs->[0]->{title__sort}, ['Title: first record Title: first record'], 'First document title__sort field should be set correctly'); |
339 |
|
338 |
|
340 |
is(scalar @{$docs->[0][1]->{title_wildcard}}, 2, 'First document title_wildcard field should have two values'); |
339 |
is(scalar @{$docs->[0]->{title_wildcard}}, 2, 'First document title_wildcard field should have two values'); |
341 |
is_deeply($docs->[0][1]->{title_wildcard}, ['Title:', 'first record'], 'First document title_wildcard field should be set correctly'); |
340 |
is_deeply($docs->[0]->{title_wildcard}, ['Title:', 'first record'], 'First document title_wildcard field should be set correctly'); |
342 |
|
341 |
|
343 |
is(scalar @{$docs->[0][1]->{author__suggestion}}, 2, 'First document author__suggestion field should contain two values'); |
342 |
is(scalar @{$docs->[0]->{author__suggestion}}, 2, 'First document author__suggestion field should contain two values'); |
344 |
is_deeply( |
343 |
is_deeply( |
345 |
$docs->[0][1]->{author__suggestion}, |
344 |
$docs->[0]->{author__suggestion}, |
346 |
[ |
345 |
[ |
347 |
{ |
346 |
{ |
348 |
'input' => 'Author 1' |
347 |
'input' => 'Author 1' |
Lines 354-362
subtest 'Koha::SearchEngine::Elasticsearch::marc_records_to_documents () tests'
Link Here
|
354 |
'First document author__suggestion field should be set correctly' |
353 |
'First document author__suggestion field should be set correctly' |
355 |
); |
354 |
); |
356 |
|
355 |
|
357 |
is(scalar @{$docs->[0][1]->{title__suggestion}}, 3, 'First document title__suggestion field should contain three values'); |
356 |
is(scalar @{$docs->[0]->{title__suggestion}}, 3, 'First document title__suggestion field should contain three values'); |
358 |
is_deeply( |
357 |
is_deeply( |
359 |
$docs->[0][1]->{title__suggestion}, |
358 |
$docs->[0]->{title__suggestion}, |
360 |
[ |
359 |
[ |
361 |
{ 'input' => 'Title:' }, |
360 |
{ 'input' => 'Title:' }, |
362 |
{ 'input' => 'first record' }, |
361 |
{ 'input' => 'first record' }, |
Lines 365-451
subtest 'Koha::SearchEngine::Elasticsearch::marc_records_to_documents () tests'
Link Here
|
365 |
'First document title__suggestion field should be set correctly' |
364 |
'First document title__suggestion field should be set correctly' |
366 |
); |
365 |
); |
367 |
|
366 |
|
368 |
ok(!(defined $docs->[0][1]->{title__facet}), 'First document should have no title__facet field'); |
367 |
ok(!(defined $docs->[0]->{title__facet}), 'First document should have no title__facet field'); |
369 |
|
368 |
|
370 |
is(scalar @{$docs->[0][1]->{author__facet}}, 2, 'First document author__facet field should have two values'); |
369 |
is(scalar @{$docs->[0]->{author__facet}}, 2, 'First document author__facet field should have two values'); |
371 |
is_deeply( |
370 |
is_deeply( |
372 |
$docs->[0][1]->{author__facet}, |
371 |
$docs->[0]->{author__facet}, |
373 |
['Author 1', 'Corp Author'], |
372 |
['Author 1', 'Corp Author'], |
374 |
'First document author__facet field should be set correctly' |
373 |
'First document author__facet field should be set correctly' |
375 |
); |
374 |
); |
376 |
|
375 |
|
377 |
is(scalar @{$docs->[0][1]->{items_withdrawn_status}}, 2, 'First document items_withdrawn_status field should have two values'); |
376 |
is(scalar @{$docs->[0]->{items_withdrawn_status}}, 2, 'First document items_withdrawn_status field should have two values'); |
378 |
is_deeply( |
377 |
is_deeply( |
379 |
$docs->[0][1]->{items_withdrawn_status}, |
378 |
$docs->[0]->{items_withdrawn_status}, |
380 |
['false', 'true'], |
379 |
['false', 'true'], |
381 |
'First document items_withdrawn_status field should be set correctly' |
380 |
'First document items_withdrawn_status field should be set correctly' |
382 |
); |
381 |
); |
383 |
|
382 |
|
384 |
is( |
383 |
is( |
385 |
$docs->[0][1]->{sum_item_price}, |
384 |
$docs->[0]->{sum_item_price}, |
386 |
'250.5', |
385 |
'250.5', |
387 |
'First document sum_item_price field should be set correctly' |
386 |
'First document sum_item_price field should be set correctly' |
388 |
); |
387 |
); |
389 |
|
388 |
|
390 |
ok(defined $docs->[0][1]->{marc_data}, 'First document marc_data field should be set'); |
389 |
ok(defined $docs->[0]->{marc_data}, 'First document marc_data field should be set'); |
391 |
ok(defined $docs->[0][1]->{marc_format}, 'First document marc_format field should be set'); |
390 |
ok(defined $docs->[0]->{marc_format}, 'First document marc_format field should be set'); |
392 |
is($docs->[0][1]->{marc_format}, 'base64ISO2709', 'First document marc_format should be set correctly'); |
391 |
is($docs->[0]->{marc_format}, 'base64ISO2709', 'First document marc_format should be set correctly'); |
393 |
|
392 |
|
394 |
my $decoded_marc_record = $see->decode_record_from_result($docs->[0][1]); |
393 |
my $decoded_marc_record = $see->decode_record_from_result($docs->[0]); |
395 |
|
394 |
|
396 |
ok($decoded_marc_record->isa('MARC::Record'), "base64ISO2709 record successfully decoded from result"); |
395 |
ok($decoded_marc_record->isa('MARC::Record'), "base64ISO2709 record successfully decoded from result"); |
397 |
is($decoded_marc_record->as_usmarc(), $marc_record_1->as_usmarc(), "Decoded base64ISO2709 record has same data as original record"); |
396 |
is($decoded_marc_record->as_usmarc(), $marc_record_1->as_usmarc(), "Decoded base64ISO2709 record has same data as original record"); |
398 |
|
397 |
|
399 |
is(scalar @{$docs->[0][1]->{type_of_record}}, 1, 'First document type_of_record field should have one value'); |
398 |
is(scalar @{$docs->[0]->{type_of_record}}, 1, 'First document type_of_record field should have one value'); |
400 |
is_deeply( |
399 |
is_deeply( |
401 |
$docs->[0][1]->{type_of_record}, |
400 |
$docs->[0]->{type_of_record}, |
402 |
['a'], |
401 |
['a'], |
403 |
'First document type_of_record field should be set correctly' |
402 |
'First document type_of_record field should be set correctly' |
404 |
); |
403 |
); |
405 |
|
404 |
|
406 |
is(scalar @{$docs->[0][1]->{type_of_record_and_bib_level}}, 1, 'First document type_of_record_and_bib_level field should have one value'); |
405 |
is(scalar @{$docs->[0]->{type_of_record_and_bib_level}}, 1, 'First document type_of_record_and_bib_level field should have one value'); |
407 |
is_deeply( |
406 |
is_deeply( |
408 |
$docs->[0][1]->{type_of_record_and_bib_level}, |
407 |
$docs->[0]->{type_of_record_and_bib_level}, |
409 |
['am'], |
408 |
['am'], |
410 |
'First document type_of_record_and_bib_level field should be set correctly' |
409 |
'First document type_of_record_and_bib_level field should be set correctly' |
411 |
); |
410 |
); |
412 |
|
411 |
|
413 |
is(scalar @{$docs->[0][1]->{isbn}}, 4, 'First document isbn field should contain four values'); |
412 |
is(scalar @{$docs->[0]->{isbn}}, 4, 'First document isbn field should contain four values'); |
414 |
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'); |
413 |
is_deeply($docs->[0]->{isbn}, ['978-1-56619-909-4', '9781566199094', '1-56619-909-3', '1566199093'], 'First document isbn field should be set correctly'); |
415 |
|
414 |
|
416 |
is_deeply( |
415 |
is_deeply( |
417 |
$docs->[0][1]->{'local_classification'}, |
416 |
$docs->[0]->{'local_classification'}, |
418 |
[$callno, $callno2, $long_callno], |
417 |
[$callno, $callno2, $long_callno], |
419 |
'First document local_classification field should be set correctly' |
418 |
'First document local_classification field should be set correctly' |
420 |
); |
419 |
); |
421 |
|
420 |
|
422 |
# Second record: |
421 |
# Second record: |
423 |
|
422 |
|
424 |
is(scalar @{$docs->[1][1]->{author}}, 1, 'Second document author field should contain one value'); |
423 |
is(scalar @{$docs->[1]->{author}}, 1, 'Second document author field should contain one value'); |
425 |
is_deeply($docs->[1][1]->{author}, ['Author 2'], 'Second document author field should be set correctly'); |
424 |
is_deeply($docs->[1]->{author}, ['Author 2'], 'Second document author field should be set correctly'); |
426 |
|
425 |
|
427 |
is(scalar @{$docs->[1][1]->{items_withdrawn_status}}, 1, 'Second document items_withdrawn_status field should have one value'); |
426 |
is(scalar @{$docs->[1]->{items_withdrawn_status}}, 1, 'Second document items_withdrawn_status field should have one value'); |
428 |
is_deeply( |
427 |
is_deeply( |
429 |
$docs->[1][1]->{items_withdrawn_status}, |
428 |
$docs->[1]->{items_withdrawn_status}, |
430 |
['true'], |
429 |
['true'], |
431 |
'Second document items_withdrawn_status field should be set correctly' |
430 |
'Second document items_withdrawn_status field should be set correctly' |
432 |
); |
431 |
); |
433 |
|
432 |
|
434 |
is( |
433 |
is( |
435 |
$docs->[1][1]->{sum_item_price}, |
434 |
$docs->[1]->{sum_item_price}, |
436 |
0, |
435 |
0, |
437 |
'Second document sum_item_price field should be set correctly' |
436 |
'Second document sum_item_price field should be set correctly' |
438 |
); |
437 |
); |
439 |
|
438 |
|
440 |
is_deeply( |
439 |
is_deeply( |
441 |
$docs->[1][1]->{local_classification__sort}, |
440 |
$docs->[1]->{local_classification__sort}, |
442 |
[substr($long_callno, 0, 255)], |
441 |
[substr($long_callno, 0, 255)], |
443 |
'Second document local_classification__sort field should be set correctly' |
442 |
'Second document local_classification__sort field should be set correctly' |
444 |
); |
443 |
); |
445 |
|
444 |
|
446 |
# Mappings marc_type: |
445 |
# Mappings marc_type: |
447 |
|
446 |
|
448 |
ok(!(defined $docs->[0][1]->{unimarc_title}), "No mapping when marc_type doesn't match marc flavour"); |
447 |
ok(!(defined $docs->[0]->{unimarc_title}), "No mapping when marc_type doesn't match marc flavour"); |
449 |
|
448 |
|
450 |
# Marc serialization format fallback for records exceeding ISO2709 max record size |
449 |
# Marc serialization format fallback for records exceeding ISO2709 max record size |
451 |
|
450 |
|
Lines 468-476
subtest 'Koha::SearchEngine::Elasticsearch::marc_records_to_documents () tests'
Link Here
|
468 |
|
467 |
|
469 |
$docs = $see->marc_records_to_documents([$large_marc_record]); |
468 |
$docs = $see->marc_records_to_documents([$large_marc_record]); |
470 |
|
469 |
|
471 |
is($docs->[0][1]->{marc_format}, 'MARCXML', 'For record exceeding max record size marc_format should be set correctly'); |
470 |
is($docs->[0]->{marc_format}, 'MARCXML', 'For record exceeding max record size marc_format should be set correctly'); |
472 |
|
471 |
|
473 |
$decoded_marc_record = $see->decode_record_from_result($docs->[0][1]); |
472 |
$decoded_marc_record = $see->decode_record_from_result($docs->[0]); |
474 |
|
473 |
|
475 |
ok($decoded_marc_record->isa('MARC::Record'), "MARCXML record successfully decoded from result"); |
474 |
ok($decoded_marc_record->isa('MARC::Record'), "MARCXML record successfully decoded from result"); |
476 |
is($decoded_marc_record->as_xml_record(), $large_marc_record->as_xml_record(), "Decoded MARCXML record has same data as original record"); |
475 |
is($decoded_marc_record->as_xml_record(), $large_marc_record->as_xml_record(), "Decoded MARCXML record has same data as original record"); |
Lines 521-527
subtest 'Koha::SearchEngine::Elasticsearch::marc_records_to_documents () tests'
Link Here
|
521 |
|
520 |
|
522 |
subtest 'Koha::SearchEngine::Elasticsearch::marc_records_to_documents_array () tests' => sub { |
521 |
subtest 'Koha::SearchEngine::Elasticsearch::marc_records_to_documents_array () tests' => sub { |
523 |
|
522 |
|
524 |
plan tests => 6; |
523 |
plan tests => 5; |
525 |
|
524 |
|
526 |
t::lib::Mocks::mock_preference('marcflavour', 'MARC21'); |
525 |
t::lib::Mocks::mock_preference('marcflavour', 'MARC21'); |
527 |
t::lib::Mocks::mock_preference('ElasticsearchMARCFormat', 'ARRAY'); |
526 |
t::lib::Mocks::mock_preference('ElasticsearchMARCFormat', 'ARRAY'); |
Lines 588-600
subtest 'Koha::SearchEngine::Elasticsearch::marc_records_to_documents_array () t
Link Here
|
588 |
# First record: |
587 |
# First record: |
589 |
is(scalar @{$docs}, 2, 'Two records converted to documents'); |
588 |
is(scalar @{$docs}, 2, 'Two records converted to documents'); |
590 |
|
589 |
|
591 |
is($docs->[0][0], '1234567', 'First document biblionumber should be set as first element in document touple'); |
590 |
is_deeply($docs->[0]->{control_number}, ['123'], 'First record control number should be set correctly'); |
592 |
|
591 |
|
593 |
is_deeply($docs->[0][1]->{control_number}, ['123'], 'First record control number should be set correctly'); |
592 |
is($docs->[0]->{marc_format}, 'ARRAY', 'First document marc_format should be set correctly'); |
594 |
|
593 |
|
595 |
is($docs->[0][1]->{marc_format}, 'ARRAY', 'First document marc_format should be set correctly'); |
594 |
my $decoded_marc_record = $see->decode_record_from_result($docs->[0]); |
596 |
|
|
|
597 |
my $decoded_marc_record = $see->decode_record_from_result($docs->[0][1]); |
598 |
|
595 |
|
599 |
ok($decoded_marc_record->isa('MARC::Record'), "ARRAY record successfully decoded from result"); |
596 |
ok($decoded_marc_record->isa('MARC::Record'), "ARRAY record successfully decoded from result"); |
600 |
is($decoded_marc_record->as_usmarc(), $marc_record_1->as_usmarc(), "Decoded ARRAY record has same data as original record"); |
597 |
is($decoded_marc_record->as_usmarc(), $marc_record_1->as_usmarc(), "Decoded ARRAY record has same data as original record"); |
601 |
- |
|
|