3 # This file is part of Koha.
5 # Koha is free software; you can redistribute it and/or modify it
6 # under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 3 of the License, or
8 # (at your option) any later version.
10 # Koha is distributed in the hope that it will be useful, but
11 # WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with Koha; if not, see <http://www.gnu.org/licenses>.
20 use Test::More tests => 6;
24 use t::lib::TestBuilder;
30 use List::Util qw( any );
32 use Koha::SearchEngine::Elasticsearch;
33 use Koha::SearchEngine::Elasticsearch::Search;
35 my $schema = Koha::Database->new->schema;
36 $schema->storage->txn_begin;
38 subtest '_read_configuration() tests' => sub {
43 t::lib::Mocks::mock_config( 'elasticsearch', undef );
45 # 'elasticsearch' missing in configuration
47 $configuration = Koha::SearchEngine::Elasticsearch::_read_configuration;
49 'Koha::Exceptions::Config::MissingEntry',
50 'Configuration problem, exception thrown';
53 "Missing <elasticsearch> entry in koha-conf.xml",
54 'Exception message is correct'
57 # 'elasticsearch' present but no 'server' entry
58 t::lib::Mocks::mock_config( 'elasticsearch', {} );
60 $configuration = Koha::SearchEngine::Elasticsearch::_read_configuration;
62 'Koha::Exceptions::Config::MissingEntry',
63 'Configuration problem, exception thrown';
66 "Missing <elasticsearch>/<server> entry in koha-conf.xml",
67 'Exception message is correct'
70 # 'elasticsearch' and 'server' entries present, but no 'index_name'
71 t::lib::Mocks::mock_config( 'elasticsearch', { server => 'a_server' } );
73 $configuration = Koha::SearchEngine::Elasticsearch::_read_configuration;
75 'Koha::Exceptions::Config::MissingEntry',
76 'Configuration problem, exception thrown';
79 "Missing <elasticsearch>/<index_name> entry in koha-conf.xml",
80 'Exception message is correct'
83 # Correct configuration, only one server
84 t::lib::Mocks::mock_config( 'elasticsearch', { server => 'a_server', index_name => 'index' } );
86 $configuration = Koha::SearchEngine::Elasticsearch::_read_configuration;
87 is( $configuration->{index_name}, 'index', 'Index configuration parsed correctly' );
88 is_deeply( $configuration->{nodes}, ['a_server'], 'Server configuration parsed correctly' );
90 # Correct configuration, two servers
91 my @servers = ('a_server', 'another_server');
92 t::lib::Mocks::mock_config( 'elasticsearch', { server => \@servers, index_name => 'index' } );
94 $configuration = Koha::SearchEngine::Elasticsearch::_read_configuration;
95 is( $configuration->{index_name}, 'index', 'Index configuration parsed correctly' );
96 is( $configuration->{cxn_pool}, 'Static', 'cxn_pool configuration set correctly to Static if not specified' );
97 is_deeply( $configuration->{nodes}, \@servers , 'Server configuration parsed correctly' );
99 t::lib::Mocks::mock_config( 'elasticsearch', { server => \@servers, index_name => 'index', cxn_pool => 'Fluid' } );
101 $configuration = Koha::SearchEngine::Elasticsearch::_read_configuration;
102 is( $configuration->{cxn_pool}, 'Fluid', 'cxn_pool configuration parsed correctly' );
103 isnt( defined $configuration->{trace_to}, 'trace_to is not defined if not set' );
105 my $params = Koha::SearchEngine::Elasticsearch::get_elasticsearch_params;
106 is_deeply( $configuration->{nodes}, \@servers , 'get_elasticsearch_params is just a wrapper for _read_configuration' );
108 t::lib::Mocks::mock_config( 'elasticsearch', { server => \@servers, index_name => 'index', cxn_pool => 'Fluid', trace_to => 'Stderr' } );
110 $configuration = Koha::SearchEngine::Elasticsearch::_read_configuration;
111 is( $configuration->{trace_to}, 'Stderr', 'trace_to configuration parsed correctly' );
114 subtest 'get_elasticsearch_settings() tests' => sub {
120 # test reading index settings
121 my $es = Koha::SearchEngine::Elasticsearch->new( {index => $Koha::SearchEngine::Elasticsearch::BIBLIOS_INDEX} );
122 $settings = $es->get_elasticsearch_settings();
123 is( $settings->{index}{analysis}{analyzer}{analyzer_phrase}{tokenizer}, 'keyword', 'Index settings parsed correctly' );
126 subtest 'get_elasticsearch_mappings() tests' => sub {
132 # test reading mappings
133 my $es = Koha::SearchEngine::Elasticsearch->new( {index => $Koha::SearchEngine::Elasticsearch::BIBLIOS_INDEX} );
134 $mappings = $es->get_elasticsearch_mappings();
135 is( $mappings->{data}{properties}{isbn__sort}{index}, 'false', 'Field mappings parsed correctly' );
138 subtest 'Koha::SearchEngine::Elasticsearch::marc_records_to_documents () tests' => sub {
142 t::lib::Mocks::mock_preference('marcflavour', 'MARC21');
143 t::lib::Mocks::mock_preference('ElasticsearchMARCFormat', 'ISO2709');
147 name => 'control_number',
153 marc_type => 'marc21',
163 marc_type => 'marc21',
164 marc_field => '020a',
173 marc_type => 'marc21',
174 marc_field => '100a',
183 marc_type => 'marc21',
184 marc_field => '110a',
193 marc_type => 'marc21',
194 marc_field => '245(ab)ab',
197 name => 'unimarc_title',
203 marc_type => 'unimarc',
204 marc_field => '245a',
210 suggestible => undef,
213 marc_type => 'marc21',
217 name => 'uniform_title',
223 marc_type => 'marc21',
224 marc_field => '240a',
227 name => 'title_wildcard',
233 marc_type => 'marc21',
237 name => 'sum_item_price',
243 marc_type => 'marc21',
244 marc_field => '952g',
247 name => 'items_withdrawn_status',
253 marc_type => 'marc21',
254 marc_field => '9520',
257 name => 'local_classification',
263 marc_type => 'marc21',
264 marc_field => '952o',
267 name => 'type_of_record',
273 marc_type => 'marc21',
274 marc_field => 'leader_/6',
277 name => 'type_of_record_and_bib_level',
283 marc_type => 'marc21',
284 marc_field => 'leader_/6-7',
293 marc_type => 'marc21',
294 marc_field => '007_/0',
303 marc_type => 'marc21',
304 marc_field => '952l',
313 marc_type => 'marc21',
314 marc_field => '260c',
317 name => 'date-of-publication',
323 marc_type => 'marc21',
324 marc_field => '008_/7-10',
333 marc_type => 'marc21',
334 marc_field => '650(avxyz)',
338 my $se = Test::MockModule->new('Koha::SearchEngine::Elasticsearch');
339 $se->mock('_foreach_mapping', sub {
340 my ($self, $sub) = @_;
342 foreach my $map (@mappings) {
356 my $see = Koha::SearchEngine::Elasticsearch::Search->new({ index => $Koha::SearchEngine::Elasticsearch::BIBLIOS_INDEX });
358 my $callno = 'ABC123';
359 my $callno2 = 'ABC456';
360 my $long_callno = '1234567890' x 30;
362 my $marc_record_1 = MARC::Record->new();
363 $marc_record_1->leader(' cam 22 a 4500');
364 $marc_record_1->append_fields(
365 MARC::Field->new('001', '123'),
366 MARC::Field->new('007', 'ku'),
367 MARC::Field->new('008', '901111s1962 xxk|||| |00| ||eng c'),
368 MARC::Field->new('020', '', '', a => '1-56619-909-3'),
369 MARC::Field->new('100', '', '', a => 'Author 1'),
370 MARC::Field->new('110', '', '', a => 'Corp Author'),
371 MARC::Field->new('210', '', '', a => 'Title 1'),
372 MARC::Field->new('240', '', '4', a => 'The uniform title with nonfiling indicator'),
373 MARC::Field->new('245', '', '', a => 'Title:', b => 'first record'),
374 MARC::Field->new('260', '', '', a => 'New York :', b => 'Ace ,', c => 'c1962'),
375 MARC::Field->new('650', '', '', a => 'Heading', z => 'Geohead', v => 'Formhead'),
376 MARC::Field->new('650', '', '', a => 'Heading', x => 'Gensubhead', z => 'Geohead'),
377 MARC::Field->new('999', '', '', c => '1234567'),
378 # ' ' for testing trimming of white space in boolean value callback:
379 MARC::Field->new('952', '', '', 0 => ' ', g => '123.30', o => $callno, l => 3),
380 MARC::Field->new('952', '', '', 0 => 0, g => '127.20', o => $callno2, l => 2),
381 MARC::Field->new('952', '', '', 0 => 1, g => '0.00', o => $long_callno, l => 1),
383 my $marc_record_2 = MARC::Record->new();
384 $marc_record_2->leader(' cam 22 a 4500');
385 $marc_record_2->append_fields(
386 MARC::Field->new('008', '901111s19uu xxk|||| |00| ||eng c'),
387 MARC::Field->new('100', '', '', a => 'Author 2'),
388 # MARC::Field->new('210', '', '', a => 'Title 2'),
389 # MARC::Field->new('245', '', '', a => 'Title: second record'),
390 MARC::Field->new('260', '', '', a => 'New York :', b => 'Ace ,', c => '1963-2003'),
391 MARC::Field->new('999', '', '', c => '1234568'),
392 MARC::Field->new('952', '', '', 0 => 1, g => 'string where should be numeric', o => $long_callno),
395 my $marc_record_3 = MARC::Record->new();
396 $marc_record_3->leader(' cam 22 a 4500');
397 $marc_record_3->append_fields(
398 MARC::Field->new('008', '901111s19uu xxk|||| |00| ||eng c'),
399 MARC::Field->new('100', '', '', a => 'Author 2'),
400 # MARC::Field->new('210', '', '', a => 'Title 3'),
401 # MARC::Field->new('245', '', '', a => 'Title: third record'),
402 MARC::Field->new('260', '', '', a => 'New York :', b => 'Ace ,', c => ' 89 '),
403 MARC::Field->new('999', '', '', c => '1234568'),
404 MARC::Field->new('952', '', '', 0 => 1, g => 'string where should be numeric', o => $long_callno),
406 my $records = [$marc_record_1, $marc_record_2, $marc_record_3];
408 $see->get_elasticsearch_mappings(); #sort_fields will call this and use the actual db values unless we call it first
410 my $docs = $see->marc_records_to_documents($records);
413 is(scalar @{$docs}, 3, 'Two records converted to documents');
415 is_deeply($docs->[0]->{control_number}, ['123'], 'First record control number should be set correctly');
417 is_deeply($docs->[0]->{'ff7-00'}, ['k'], 'First record ff7-00 should be set correctly');
419 is(scalar @{$docs->[0]->{author}}, 2, 'First document author field should contain two values');
420 is_deeply($docs->[0]->{author}, ['Author 1', 'Corp Author'], 'First document author field should be set correctly');
422 is(scalar @{$docs->[0]->{subject}}, 2, 'First document subject field should contain two values');
423 is_deeply($docs->[0]->{subject}, ['Heading Geohead Formhead', 'Heading Gensubhead Geohead'], 'First document asubject field should be set correctly, record order preserved for grouped subfield mapping');
425 is(scalar @{$docs->[0]->{author__sort}}, 1, 'First document author__sort field should have a single value');
426 is_deeply($docs->[0]->{author__sort}, ['Author 1 Corp Author'], 'First document author__sort field should be set correctly');
428 is(scalar @{$docs->[0]->{title__sort}}, 1, 'First document title__sort field should have a single');
429 is_deeply($docs->[0]->{title__sort}, ['Title: first record Title: first record'], 'First document title__sort field should be set correctly');
431 is($docs->[0]->{issues}, 6, 'Issues field should be sum of the issues for each item');
432 is($docs->[0]->{issues__sort}, 6, 'Issues sort field should also be a sum of the issues');
434 is(scalar @{$docs->[0]->{title_wildcard}}, 2, 'First document title_wildcard field should have two values');
435 is_deeply($docs->[0]->{title_wildcard}, ['Title:', 'first record'], 'First document title_wildcard field should be set correctly');
438 is(scalar @{$docs->[0]->{author__suggestion}}, 2, 'First document author__suggestion field should contain two values');
440 $docs->[0]->{author__suggestion},
443 'input' => 'Author 1'
446 'input' => 'Corp Author'
449 'First document author__suggestion field should be set correctly'
452 is(scalar @{$docs->[0]->{title__suggestion}}, 3, 'First document title__suggestion field should contain three values');
454 $docs->[0]->{title__suggestion},
456 { 'input' => 'Title:' },
457 { 'input' => 'first record' },
458 { 'input' => 'Title: first record' }
460 'First document title__suggestion field should be set correctly'
463 ok(!(defined $docs->[0]->{title__facet}), 'First document should have no title__facet field');
465 is(scalar @{$docs->[0]->{author__facet}}, 2, 'First document author__facet field should have two values');
467 $docs->[0]->{author__facet},
468 ['Author 1', 'Corp Author'],
469 'First document author__facet field should be set correctly'
472 is(scalar @{$docs->[0]->{items_withdrawn_status}}, 2, 'First document items_withdrawn_status field should have two values');
474 $docs->[0]->{items_withdrawn_status},
476 'First document items_withdrawn_status field should be set correctly'
480 $docs->[0]->{sum_item_price},
482 'First document sum_item_price field should be set correctly'
485 ok(defined $docs->[0]->{marc_data}, 'First document marc_data field should be set');
486 ok(defined $docs->[0]->{marc_format}, 'First document marc_format field should be set');
487 is($docs->[0]->{marc_format}, 'base64ISO2709', 'First document marc_format should be set correctly');
489 my $decoded_marc_record = $see->decode_record_from_result($docs->[0]);
491 ok($decoded_marc_record->isa('MARC::Record'), "base64ISO2709 record successfully decoded from result");
492 is($decoded_marc_record->as_usmarc(), $marc_record_1->as_usmarc(), "Decoded base64ISO2709 record has same data as original record");
494 is(scalar @{$docs->[0]->{type_of_record}}, 1, 'First document type_of_record field should have one value');
496 $docs->[0]->{type_of_record},
498 'First document type_of_record field should be set correctly'
501 is(scalar @{$docs->[0]->{type_of_record_and_bib_level}}, 1, 'First document type_of_record_and_bib_level field should have one value');
503 $docs->[0]->{type_of_record_and_bib_level},
505 'First document type_of_record_and_bib_level field should be set correctly'
508 is(scalar @{$docs->[0]->{isbn}}, 4, 'First document isbn field should contain four values');
509 is_deeply($docs->[0]->{isbn}, ['978-1-56619-909-4', '9781566199094', '1-56619-909-3', '1566199093'], 'First document isbn field should be set correctly');
512 $docs->[0]->{'local_classification'},
513 [$callno, $callno2, $long_callno],
514 'First document local_classification field should be set correctly'
517 # Nonfiling characters for sort fields
519 $docs->[0]->{uniform_title},
520 ['The uniform title with nonfiling indicator'],
521 'First document uniform_title field should contain the title verbatim'
524 $docs->[0]->{uniform_title__sort},
525 ['uniform title with nonfiling indicator'],
526 'First document uniform_title__sort field should contain the title with the first four initial characters removed'
529 # Tests for 'year' type
530 is(scalar @{$docs->[0]->{'date-of-publication'}}, 1, 'First document date-of-publication field should contain one value');
531 is_deeply($docs->[0]->{'date-of-publication'}, ['1962'], 'First document date-of-publication field should be set correctly');
534 $docs->[0]->{'copydate'},
536 'First document copydate field should be set correctly'
541 is(scalar @{$docs->[1]->{author}}, 1, 'Second document author field should contain one value');
542 is_deeply($docs->[1]->{author}, ['Author 2'], 'Second document author field should be set correctly');
544 is(scalar @{$docs->[1]->{items_withdrawn_status}}, 1, 'Second document items_withdrawn_status field should have one value');
546 $docs->[1]->{items_withdrawn_status},
548 'Second document items_withdrawn_status field should be set correctly'
552 $docs->[1]->{sum_item_price},
554 'Second document sum_item_price field should be set correctly'
558 $docs->[1]->{local_classification__sort},
559 [substr($long_callno, 0, 255)],
560 'Second document local_classification__sort field should be set correctly'
563 # Tests for 'year' type
565 $docs->[1]->{'copydate'},
567 'Second document copydate field should be set correctly'
570 $docs->[1]->{'date-of-publication'},
572 'Second document date-of-publication field should be set correctly'
578 $docs->[2]->{'copydate'},
580 'Third document copydate field should be set correctly'
583 # Mappings marc_type:
585 ok(!(defined $docs->[0]->{unimarc_title}), "No mapping when marc_type doesn't match marc flavour");
587 # Marc serialization format fallback for records exceeding ISO2709 max record size
589 my $large_marc_record = MARC::Record->new();
590 $large_marc_record->leader(' cam 22 a 4500');
592 $large_marc_record->append_fields(
593 MARC::Field->new('100', '', '', a => 'Author 1'),
594 MARC::Field->new('110', '', '', a => 'Corp Author'),
595 MARC::Field->new('210', '', '', a => 'Title 1'),
596 MARC::Field->new('245', '', '', a => 'Title:', b => 'large record'),
597 MARC::Field->new('999', '', '', c => '1234567'),
600 my $item_field = MARC::Field->new('952', '', '', o => '123456789123456789123456789', p => '123456789', z => 'test');
601 my $items_count = 1638;
602 while(--$items_count) {
603 $large_marc_record->append_fields($item_field);
606 $docs = $see->marc_records_to_documents([$large_marc_record]);
608 is($docs->[0]->{marc_format}, 'MARCXML', 'For record exceeding max record size marc_format should be set correctly');
610 $decoded_marc_record = $see->decode_record_from_result($docs->[0]);
612 ok($decoded_marc_record->isa('MARC::Record'), "MARCXML record successfully decoded from result");
613 is($decoded_marc_record->as_xml_record(), $large_marc_record->as_xml_record(), "Decoded MARCXML record has same data as original record");
621 marc_type => 'marc21',
622 marc_field => '245((ab)ab',
625 my $exception = try {
626 $see->marc_records_to_documents($records);
632 ok(defined $exception, "Exception has been thrown when processing mapping with unmatched opening parenthesis");
633 ok($exception->isa("Koha::Exceptions::Elasticsearch::MARCFieldExprParseError"), "Exception is of correct class");
634 ok($exception->message =~ /Unmatched opening parenthesis/, "Exception has the correct message");
643 marc_type => 'marc21',
644 marc_field => '245(ab))ab',
648 $see->marc_records_to_documents($records);
654 ok(defined $exception, "Exception has been thrown when processing mapping with unmatched closing parenthesis");
655 ok($exception->isa("Koha::Exceptions::Elasticsearch::MARCFieldExprParseError"), "Exception is of correct class");
656 ok($exception->message =~ /Unmatched closing parenthesis/, "Exception has the correct message");
659 my $marc_record_with_blank_field = MARC::Record->new();
660 $marc_record_with_blank_field->leader(' cam 22 a 4500');
662 $marc_record_with_blank_field->append_fields(
663 MARC::Field->new('100', '', '', a => ''),
664 MARC::Field->new('210', '', '', a => 'Title 1'),
665 MARC::Field->new('245', '', '', a => 'Title:', b => 'large record'),
666 MARC::Field->new('999', '', '', c => '1234567'),
668 $docs = $see->marc_records_to_documents([$marc_record_with_blank_field]);
669 is_deeply( $docs->[0]->{author},[],'No value placed into field if mapped marc field is blank');
670 is_deeply( $docs->[0]->{author__suggestion},[],'No value placed into suggestion if mapped marc field is blank');
674 subtest 'Koha::SearchEngine::Elasticsearch::marc_records_to_documents_array () tests' => sub {
678 t::lib::Mocks::mock_preference('marcflavour', 'MARC21');
679 t::lib::Mocks::mock_preference('ElasticsearchMARCFormat', 'ARRAY');
683 name => 'control_number',
689 marc_type => 'marc21',
694 my $se = Test::MockModule->new('Koha::SearchEngine::Elasticsearch');
695 $se->mock('_foreach_mapping', sub {
696 my ($self, $sub) = @_;
698 foreach my $map (@mappings) {
712 my $see = Koha::SearchEngine::Elasticsearch::Search->new({ index => $Koha::SearchEngine::Elasticsearch::BIBLIOS_INDEX });
714 my $marc_record_1 = MARC::Record->new();
715 $marc_record_1->leader(' cam 22 a 4500');
716 $marc_record_1->append_fields(
717 MARC::Field->new('001', '123'),
718 MARC::Field->new('020', '', '', a => '1-56619-909-3'),
719 MARC::Field->new('100', '', '', a => 'Author 1'),
720 MARC::Field->new('110', '', '', a => 'Corp Author'),
721 MARC::Field->new('210', '', '', a => 'Title 1'),
722 MARC::Field->new('245', '', '', a => 'Title:', b => 'first record'),
723 MARC::Field->new('999', '', '', c => '1234567'),
725 my $marc_record_2 = MARC::Record->new();
726 $marc_record_2->leader(' cam 22 a 4500');
727 $marc_record_2->append_fields(
728 MARC::Field->new('100', '', '', a => 'Author 2'),
729 # MARC::Field->new('210', '', '', a => 'Title 2'),
730 # MARC::Field->new('245', '', '', a => 'Title: second record'),
731 MARC::Field->new('999', '', '', c => '1234568'),
732 MARC::Field->new('952', '', '', 0 => 1, g => 'string where should be numeric'),
734 my $records = [ $marc_record_1, $marc_record_2 ];
736 $see->get_elasticsearch_mappings(); #sort_fields will call this and use the actual db values unless we call it first
738 my $docs = $see->marc_records_to_documents($records);
741 is(scalar @{$docs}, 2, 'Two records converted to documents');
743 is_deeply($docs->[0]->{control_number}, ['123'], 'First record control number should be set correctly');
745 is($docs->[0]->{marc_format}, 'ARRAY', 'First document marc_format should be set correctly');
747 my $decoded_marc_record = $see->decode_record_from_result($docs->[0]);
749 ok($decoded_marc_record->isa('MARC::Record'), "ARRAY record successfully decoded from result");
750 is($decoded_marc_record->as_usmarc(), $marc_record_1->as_usmarc(), "Decoded ARRAY record has same data as original record");
753 subtest 'Koha::SearchEngine::Elasticsearch::marc_records_to_documents () authority tests' => sub {
757 t::lib::Mocks::mock_preference('marcflavour', 'MARC21');
758 t::lib::Mocks::mock_preference('ElasticsearchMARCFormat', 'ISO2709');
760 my $builder = t::lib::TestBuilder->new;
761 my $auth_type = $builder->build_object({ class => 'Koha::Authority::Types', value =>{
762 auth_tag_to_report => '150'
774 marc_type => 'marc21',
775 marc_field => '150(aevxyz)',
784 marc_type => 'marc21',
785 marc_field => '185v',
789 my $se = Test::MockModule->new('Koha::SearchEngine::Elasticsearch');
790 $se->mock('_foreach_mapping', sub {
791 my ($self, $sub) = @_;
793 foreach my $map (@mappings) {
807 my $see = Koha::SearchEngine::Elasticsearch::Search->new({ index => $Koha::SearchEngine::Elasticsearch::AUTHORITIES_INDEX });
808 my $marc_record_1 = MARC::Record->new();
809 $marc_record_1->append_fields(
810 MARC::Field->new('001', '123'),
811 MARC::Field->new('007', 'ku'),
812 MARC::Field->new('020', '', '', a => '1-56619-909-3'),
813 MARC::Field->new('150', '', '', a => 'Subject', v => 'Genresubdiv', x => 'Generalsubdiv', z => 'Geosubdiv'),
815 my $marc_record_2 = MARC::Record->new();
816 $marc_record_2->append_fields(
817 MARC::Field->new('150', '', '', a => 'Subject', v => 'Genresubdiv', z => 'Geosubdiv', x => 'Generalsubdiv', e => 'wrongsubdiv' ),
819 my $marc_record_3 = MARC::Record->new();
820 $marc_record_3->append_fields(
821 MARC::Field->new('185', '', '', v => 'Formsubdiv' ),
823 my $records = [ $marc_record_1, $marc_record_2, $marc_record_3 ];
825 $see->get_elasticsearch_mappings(); #sort_fields will call this and use the actual db values unless we call it first
827 my $docs = $see->marc_records_to_documents($records);
830 [ "Subject formsubdiv Genresubdiv generalsubdiv Generalsubdiv geographicsubdiv Geosubdiv" ],
831 $docs->[0]->{'match-heading'},
832 "First record match-heading should contain the correctly formatted heading"
835 [ "Subject formsubdiv Genresubdiv geographicsubdiv Geosubdiv generalsubdiv Generalsubdiv" ],
836 $docs->[1]->{'match-heading'},
837 "Second record match-heading should contain the correctly formatted heading without wrong subfield"
840 [ "Subject Genresubdiv Geosubdiv Generalsubdiv wrongsubdiv" ],
841 $docs->[1]->{'match'} ,
842 "Second record heading should contain the subfields with record order retained"
844 ok( !exists $docs->[2]->{'match-heading'}, "No match heading defined for subdivision record");
847 $docs->[2]->{'match'} ,
848 "Third record heading should contain the subfield"
853 $schema->storage->txn_rollback;