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

(-)a/C4/Matcher.pm (-31 / +46 lines)
Lines 17-30 package C4::Matcher; Link Here
17
# You should have received a copy of the GNU General Public License
17
# You should have received a copy of the GNU General Public License
18
# along with Koha; if not, see <http://www.gnu.org/licenses>.
18
# along with Koha; if not, see <http://www.gnu.org/licenses>.
19
19
20
use strict;
20
use Modern::Perl;
21
use warnings;
22
21
23
use C4::Context;
24
use MARC::Record;
22
use MARC::Record;
25
23
26
use Koha::SearchEngine;
24
use Koha::SearchEngine;
27
use Koha::SearchEngine::Search;
25
use Koha::SearchEngine::Search;
26
use Koha::Util::Normalize qw/legacy_default remove_spaces upper_case lower_case/;
28
27
29
=head1 NAME
28
=head1 NAME
30
29
Lines 774-779 sub _passes_required_checks { Link Here
774
}
773
}
775
774
776
sub _get_match_keys {
775
sub _get_match_keys {
776
777
    my $source_record = shift;
777
    my $source_record = shift;
778
    my $matchpoint = shift;
778
    my $matchpoint = shift;
779
    my $check_only_first_repeat = @_ ? shift : 0;
779
    my $check_only_first_repeat = @_ ? shift : 0;
Lines 792-798 sub _get_match_keys { Link Here
792
    # If there are two 003s and two 001s, there will be two keys:
792
    # If there are two 003s and two 001s, there will be two keys:
793
    #    first 003 + first 001
793
    #    first 003 + first 001
794
    #    second 003 + second 001
794
    #    second 003 + second 001
795
    
795
796
    my $valid_normalization_routines = {
797
        remove_spaces => 1,
798
        upper_case => 1,
799
        lower_case => 1,
800
        legacy_default => 1
801
    };
802
796
    my @keys = ();
803
    my @keys = ();
797
    for (my $i = 0; $i <= $#{ $matchpoint->{'components'} }; $i++) {
804
    for (my $i = 0; $i <= $#{ $matchpoint->{'components'} }; $i++) {
798
        my $component = $matchpoint->{'components'}->[$i];
805
        my $component = $matchpoint->{'components'}->[$i];
Lines 801-824 sub _get_match_keys { Link Here
801
            $j++;
808
            $j++;
802
            last FIELD if $j > 0 and $check_only_first_repeat;
809
            last FIELD if $j > 0 and $check_only_first_repeat;
803
            last FIELD if $i > 0 and $j > $#keys;
810
            last FIELD if $i > 0 and $j > $#keys;
804
            my $key = "";
811
805
			my $string;
812
            my $string;
806
            if ($field->is_control_field()) {
813
            if ( $field->is_control_field() ) {
807
				$string=$field->data();
814
                $string = $field->data();
808
            } else {
815
            } else {
809
                foreach my $subfield ($field->subfields()) {
816
                $string = $field->as_string(
810
                    if (exists $component->{'subfields'}->{$subfield->[0]}) {
817
                    join('', keys %{ $component->{ subfields } }), ' ' # ' ' as separator
811
                        $string .= " " . $subfield->[1]; #FIXME: It would be better to create an array and join with a space later...
818
                );
812
                    }
819
            }
813
                }
820
814
			}
815
            if ($component->{'length'}>0) {
821
            if ($component->{'length'}>0) {
816
                    $string= substr($string, $component->{'offset'}, $component->{'length'});
822
                $string= substr($string, $component->{'offset'}, $component->{'length'});
817
                            # FIXME normalize, substr
818
            } elsif ($component->{'offset'}) {
823
            } elsif ($component->{'offset'}) {
819
                    $string= substr($string, $component->{'offset'});
824
                $string= substr($string, $component->{'offset'});
825
            }
826
827
            my $norms = $component->{'norms'};
828
            my $key = $string;
829
830
            foreach my $norm ( @{ $norms } ) {
831
                if ( $valid_normalization_routines->{$norm} ) {
832
                    if ( $norm eq 'remove_spaces' ) {
833
                        $key = remove_spaces($key);
834
                    }
835
                    elsif ( $norm eq 'upper_case' ) {
836
                        $key = upper_case($key);
837
                    }
838
                    elsif ( $norm eq 'lower_case' ) {
839
                        $key = lower_case($key);
840
                    }
841
                    elsif ( $norm eq 'legacy_default' ) {
842
                        $key = legacy_default($key);
843
                    }
844
                } else {
845
                    warn "Invalid normalization routine required ($norm)"
846
                        unless $norm eq 'none';
847
                }
820
            }
848
            }
821
            $key = _normalize($string);
849
822
            if ($i == 0) {
850
            if ($i == 0) {
823
                push @keys, $key if $key;
851
                push @keys, $key if $key;
824
            } else {
852
            } else {
Lines 843-860 sub _parse_match_component { Link Here
843
    return $component;
871
    return $component;
844
}
872
}
845
873
846
# FIXME - default normalizer
847
sub _normalize {
848
    my $value = uc shift;
849
    $value =~ s/[.;:,\]\[\)\(\/'"]//g;
850
    $value =~ s/^\s+//;
851
    #$value =~ s/^\s+$//;
852
    $value =~ s/\s+$//;
853
    $value =~ s/\s+/ /g;
854
    #$value =~ s/[.;,\]\[\)\(\/"']//g;
855
    return $value;
856
}
857
858
1;
874
1;
859
__END__
875
__END__
860
876
861
- 

Return to bug 17318