@@ -, +, @@ --- C4/Matcher.pm | 17 +++++++++++++++-- t/Matcher.t | 39 ++++++++++++++++++++++++++++++++++++++- 2 files changed, 53 insertions(+), 3 deletions(-) --- a/C4/Matcher.pm +++ a/C4/Matcher.pm @@ -812,13 +812,26 @@ sub _get_match_keys { for (my $i = 0; $i <= $#{ $matchpoint->{'components'} }; $i++) { my $component = $matchpoint->{'components'}->[$i]; my $j = -1; - FIELD: foreach my $field ($source_record->field($component->{'tag'})) { + + my @fields = (); + my $tag = $component->{'tag'}; + if ($tag && $tag eq 'LDR'){ + $fields[0] = $source_record->leader(); + } + else { + @fields = $source_record->field($tag); + } + + FIELD: foreach my $field (@fields) { $j++; last FIELD if $j > 0 and $check_only_first_repeat; last FIELD if $i > 0 and $j > $#keys; my $string; - if ( $field->is_control_field() ) { + if ( ! ref $field ){ + $string = "$field"; + } + elsif ( $field->is_control_field() ) { $string = $field->data(); } else { $string = $field->as_string( --- a/t/Matcher.t +++ a/t/Matcher.t @@ -27,7 +27,7 @@ use Module::Load::Conditional qw/check_install/; BEGIN { if ( check_install( module => 'Test::DBIx::Class' ) ) { - plan tests => 12; + plan tests => 13; } else { plan skip_all => "Need Test::DBIx::Class" } @@ -264,6 +264,23 @@ subtest '_get_match_keys() tests' => sub { }; +subtest '_get_match_keys() leader tests' => sub { + plan tests => 2; + my $record = MARC::Record->new(); + my $matchpoint = get_leader_matchpoint({ + length => 1, + offset => 6, + }); + + my @keys = C4::Matcher::_get_match_keys( $record, $matchpoint ); + is( $keys[0], ' ', 'Match key correctly calculated as " " from LDR6 when no leader available'); + + $record->leader('01344cam a22003014a 4500'); + + @keys = C4::Matcher::_get_match_keys( $record, $matchpoint ); + is( $keys[0], 'a', 'Match key correctly calculated as "a" from LDR6'); +}; + sub get_title_matchpoint { my $params = shift; @@ -358,3 +375,23 @@ sub get_isbn_matchpoint { return $matchpoint; } + +sub get_leader_matchpoint { + my $params = shift; + my $length = $params->{length} // 0; + my $norms = $params->{norms} // []; + my $offset = $params->{offset} // 0; + + my $matchpoint = { + components => [ + { + length => $length, + norms => $norms, + offset => $offset, + tag => 'LDR' + }, + ], + }; + + return $matchpoint; +} --