View | Details | Raw Unified | Return to bug 23324
Collapse All | Expand All

(-)a/C4/Matcher.pm (-2 / +6 lines)
Lines 24-30 use MARC::Record; Link Here
24
use Koha::SearchEngine;
24
use Koha::SearchEngine;
25
use Koha::SearchEngine::Search;
25
use Koha::SearchEngine::Search;
26
use Koha::SearchEngine::QueryBuilder;
26
use Koha::SearchEngine::QueryBuilder;
27
use Koha::Util::Normalize qw/legacy_default remove_spaces upper_case lower_case/;
27
use Koha::Util::Normalize qw/legacy_default remove_spaces upper_case lower_case ISBN/;
28
28
29
=head1 NAME
29
=head1 NAME
30
30
Lines 866-871 sub _get_match_keys { Link Here
866
                    elsif ( $norm eq 'legacy_default' ) {
866
                    elsif ( $norm eq 'legacy_default' ) {
867
                        $key = legacy_default($key);
867
                        $key = legacy_default($key);
868
                    }
868
                    }
869
                    elsif ( $norm eq 'ISBN' ) {
870
                        $key = ISBN($key);
871
                    }
869
                } else {
872
                } else {
870
                    warn "Invalid normalization routine required ($norm)"
873
                    warn "Invalid normalization routine required ($norm)"
871
                        unless $norm eq 'none';
874
                        unless $norm eq 'none';
Lines 902-908 sub valid_normalization_routines { Link Here
902
        'remove_spaces',
905
        'remove_spaces',
903
        'upper_case',
906
        'upper_case',
904
        'lower_case',
907
        'lower_case',
905
        'legacy_default'
908
        'legacy_default',
909
        'ISBN'
906
    );
910
    );
907
}
911
}
908
912
(-)a/Koha/Util/Normalize.pm (+21 lines)
Lines 18-23 package Koha::Util::Normalize; Link Here
18
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19
19
20
use Modern::Perl;
20
use Modern::Perl;
21
use Business::ISBN;
21
22
22
use parent qw( Exporter );
23
use parent qw( Exporter );
23
24
Lines 26-31 our @EXPORT = qw( Link Here
26
  remove_spaces
27
  remove_spaces
27
  upper_case
28
  upper_case
28
  lower_case
29
  lower_case
30
  ISBN
29
);
31
);
30
32
31
=head1 NAME
33
=head1 NAME
Lines 99-104 sub lower_case { Link Here
99
    return $string;
101
    return $string;
100
}
102
}
101
103
104
=head2 ISBN
105
106
Normalization function converting ISBN strings to ISBN13
107
If string is not a valid ISBN we pass it through unaltered
108
109
=cut
110
111
sub ISBN {
112
    my ( $string ) = @_;
113
    return if !defined( $string );
114
115
    my $isbn = Business::ISBN->new($string);
116
    if (defined $isbn && $isbn->is_valid) {
117
        $string = $isbn->as_isbn13->as_string([]);
118
    }
119
120
    return $string;
121
}
122
102
1;
123
1;
103
__END__
124
__END__
104
125
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/matching-rules.tt (+1 lines)
Lines 23-28 Link Here
23
[%        CASE 'upper_case'     %]Uppercase
23
[%        CASE 'upper_case'     %]Uppercase
24
[%        CASE 'lower_case'     %]Lowercase
24
[%        CASE 'lower_case'     %]Lowercase
25
[%        CASE 'legacy_default' %]Legacy default
25
[%        CASE 'legacy_default' %]Legacy default
26
[%        CASE 'ISBN' %]ISBN
26
[%        CASE %][% norm | html %]
27
[%        CASE %][% norm | html %]
27
[%    END %]
28
[%    END %]
28
[% END %]
29
[% END %]
(-)a/t/Matcher.t (-2 / +49 lines)
Lines 82-88 is( $testmatcher->description(), 'match on ISSN', 'testing code accessor' ); Link Here
82
82
83
subtest '_get_match_keys() tests' => sub {
83
subtest '_get_match_keys() tests' => sub {
84
84
85
    plan tests => 17;
85
    plan tests => 20;
86
86
87
    my $matchpoint = get_title_matchpoint({
87
    my $matchpoint = get_title_matchpoint({
88
        length => 0,
88
        length => 0,
Lines 92-97 subtest '_get_match_keys() tests' => sub { Link Here
92
92
93
    my $record = MARC::Record->new();
93
    my $record = MARC::Record->new();
94
    $record->append_fields(
94
    $record->append_fields(
95
        MARC::Field->new('020', '1', ' ',
96
                            a => '978-1451697216 (alk. paper)'),
97
        MARC::Field->new('020', '1', ' ',
98
                            a => '145169721X (alk. paper)'),
99
        MARC::Field->new('020', '1', ' ',
100
                            a => '1NOTISBN3'),
95
        MARC::Field->new('100', '1', ' ',
101
        MARC::Field->new('100', '1', ' ',
96
                            a => 'King, Stephen',
102
                            a => 'King, Stephen',
97
                            d => 'd1947-'),
103
                            d => 'd1947-'),
Lines 242-247 subtest '_get_match_keys() tests' => sub { Link Here
242
248
243
    is( $keys[0], '  .; THE T[]:,ALIS(M)/AN\'" STEPHEN KING, PETER STRAUB.',
249
    is( $keys[0], '  .; THE T[]:,ALIS(M)/AN\'" STEPHEN KING, PETER STRAUB.',
244
        'Match key correctly normalized if invalid normalization routine specified' );
250
        'Match key correctly normalized if invalid normalization routine specified' );
251
252
    $matchpoint = get_isbn_matchpoint({
253
        length => 0,
254
        norms  => [ 'ISBN' ],
255
        offset => 0
256
    });
257
    @keys = C4::Matcher::_get_match_keys( $record, $matchpoint );
258
    is( $keys[0], '9781451697216',
259
        'Match key correctly calculated as ISBN13 when ISBN normalizer used');
260
    is( $keys[1], '9781451697216',
261
        'Match key correctly calculated as ISBN13 when ISBN normalizer used');
262
    is( $keys[2], '1NOTISBN3',
263
        'Match key passed through if not an isbn when ISBN normalizer used');
264
245
};
265
};
246
266
247
sub get_title_matchpoint {
267
sub get_title_matchpoint {
Lines 311-313 sub get_authors_matchpoint { Link Here
311
    return $matchpoint;
331
    return $matchpoint;
312
}
332
}
313
333
314
- 
334
sub get_isbn_matchpoint {
335
336
    my $params = shift;
337
338
    my $length = $params->{length} // 0;
339
    my $norms  = $params->{norms}  // [];
340
    my $offset = $params->{offset} // 0;
341
342
    my $matchpoint = {
343
        components =>  [
344
            {
345
                length    => $length,
346
                norms     => $norms,
347
                offset    => $offset,
348
                subfields =>
349
                    {
350
                        a => 1
351
                    },
352
                tag => '020'
353
            },
354
        ],
355
        index => "isbn",
356
        score => 1000
357
    };
358
359
    return $matchpoint;
360
}
361

Return to bug 23324