$options->{property} => $_data
}
}
- # For sort fields, index only a single field with concatenated values
- if ($sort && @{$record_document->{$target}}) {
- @{$record_document->{$target}}[0] .= " $_data";
- } else {
- push @{$record_document->{$target}}, $_data;
- }
+ push @{$record_document->{$target}}, $_data;
}
}
}
}
+ # Remove duplicate values and collapse sort fields
+ foreach my $field (keys %{$record_document}) {
+ if (ref($record_document->{$field}) eq 'ARRAY') {
+ @{$record_document->{$field}} = do {
+ my %seen;
+ grep { !$seen{ref($_) eq 'HASH' && defined $_->{input} ? $_->{input} : $_}++ } @{$record_document->{$field}};
+ };
+ if ($field =~ /__sort$/) {
+ # Make sure to keep the sort field length sensible. 255 was chosen as a nice round value.
+ $record_document->{$field} = [substr(join(' ', @{$record_document->{$field}}), 0, 255)];
+ }
+ }
+ }
+
# TODO: Perhaps should check if $records_document non empty, but really should never be the case
$record->encoding('UTF-8');
my @warnings;
subtest 'Koha::SearchEngine::Elasticsearch::marc_records_to_documents () tests' => sub {
- plan tests => 47;
+ plan tests => 49;
t::lib::Mocks::mock_preference('marcflavour', 'MARC21');
marc_type => 'marc21',
marc_field => '9520',
},
+ {
+ name => 'local_classification',
+ type => 'string',
+ facet => 0,
+ suggestible => 0,
+ sort => 1,
+ marc_type => 'marc21',
+ marc_field => '952o',
+ },
{
name => 'type_of_record',
type => 'string',
my $see = Koha::SearchEngine::Elasticsearch::Search->new({ index => $Koha::SearchEngine::Elasticsearch::BIBLIOS_INDEX });
+ my $callno = 'ABC123';
+ my $callno2 = 'ABC456';
+ my $long_callno = '1234567890' x 30;
+
my $marc_record_1 = MARC::Record->new();
$marc_record_1->leader(' cam 22 a 4500');
$marc_record_1->append_fields(
MARC::Field->new('245', '', '', a => 'Title:', b => 'first record'),
MARC::Field->new('999', '', '', c => '1234567'),
# ' ' for testing trimming of white space in boolean value callback:
- MARC::Field->new('952', '', '', 0 => ' ', g => '123.30'),
- MARC::Field->new('952', '', '', 0 => 0, g => '127.20'),
+ MARC::Field->new('952', '', '', 0 => ' ', g => '123.30', o => $callno),
+ MARC::Field->new('952', '', '', 0 => 0, g => '127.20', o => $callno2),
+ MARC::Field->new('952', '', '', 0 => 1, g => '0.00', o => $long_callno),
);
my $marc_record_2 = MARC::Record->new();
$marc_record_2->leader(' cam 22 a 4500');
# MARC::Field->new('210', '', '', a => 'Title 2'),
# MARC::Field->new('245', '', '', a => 'Title: second record'),
MARC::Field->new('999', '', '', c => '1234568'),
- MARC::Field->new('952', '', '', 0 => 1, g => 'string where should be numeric'),
+ MARC::Field->new('952', '', '', 0 => 1, g => 'string where should be numeric', o => $long_callno),
);
my $records = [$marc_record_1, $marc_record_2];
is(scalar @{$docs->[0][1]->{items_withdrawn_status}}, 2, 'First document items_withdrawn_status field should have two values');
is_deeply(
$docs->[0][1]->{items_withdrawn_status},
- ['false', 'false'],
+ ['false', 'true'],
'First document items_withdrawn_status field should be set correctly'
);
is(scalar @{$docs->[0][1]->{isbn}}, 4, 'First document isbn field should contain four values');
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');
+ is_deeply(
+ $docs->[0][1]->{'local_classification'},
+ [$callno, $callno2, $long_callno],
+ 'First document local_classification field should be set correctly'
+ );
+
# Second record:
is(scalar @{$docs->[1][1]->{author}}, 1, 'Second document author field should contain one value');
'Second document sum_item_price field should be set correctly'
);
+ is_deeply(
+ $docs->[1][1]->{local_classification__sort},
+ [substr($long_callno, 0, 255)],
+ 'Second document local_classification__sort field should be set correctly'
+ );
+
# Mappings marc_type:
ok(!(defined $docs->[0][1]->{unimarc_title}), "No mapping when marc_type doesn't match marc flavour");