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

(-)a/C4/Heading.pm (-2 / +7 lines)
Lines 150-156 SearchAuthorities will return only authids. Link Here
150
sub authorities {
150
sub authorities {
151
    my $self         = shift;
151
    my $self         = shift;
152
    my $skipmetadata = shift;
152
    my $skipmetadata = shift;
153
    my ( $results, $total ) = _search( $self, 'match-heading', $skipmetadata );
153
		my $maxlength = shift || undef;
154
155
    my ( $results, $total ) = _search( $self, 'match-heading', $skipmetadata, $maxlength );
154
    return $results;
156
    return $results;
155
}
157
}
156
158
Lines 180-191 sub _search { Link Here
180
    my $self         = shift;
182
    my $self         = shift;
181
    my $index        = shift || undef;
183
    my $index        = shift || undef;
182
    my $skipmetadata = shift || undef;
184
    my $skipmetadata = shift || undef;
185
		my $maxlength    = shift || undef;
183
    my @marclist;
186
    my @marclist;
184
    my @and_or;
187
    my @and_or;
185
    my @excluding = [];
188
    my @excluding = [];
186
    my @operator;
189
    my @operator;
187
    my @value;
190
    my @value;
188
191
192
		$maxlength=20 unless $maxlength;
193
189
    if ($index) {
194
    if ($index) {
190
        push @marclist, $index;
195
        push @marclist, $index;
191
        push @and_or,   'and';
196
        push @and_or,   'and';
Lines 203-209 sub _search { Link Here
203
    require C4::AuthoritiesMarc;
208
    require C4::AuthoritiesMarc;
204
    return C4::AuthoritiesMarc::SearchAuthorities(
209
    return C4::AuthoritiesMarc::SearchAuthorities(
205
        \@marclist, \@and_or, \@excluding, \@operator,
210
        \@marclist, \@and_or, \@excluding, \@operator,
206
        \@value,    0,        20,          $self->{'auth_type'},
211
        \@value,    0,        $maxlength,          $self->{'auth_type'},
207
        'AuthidAsc',         $skipmetadata
212
        'AuthidAsc',         $skipmetadata
208
    );
213
    );
209
}
214
}
(-)a/C4/Linker/BestMatch.pm (+128 lines)
Line 0 Link Here
1
package C4::Linker::BestMatch;
2
3
# Copyright 2011 C & P Bibliography Services
4
#
5
# This file is part of Koha.
6
#
7
# Koha is free software; you can redistribute it and/or modify it
8
# under the terms of the GNU General Public License as published by
9
# the Free Software Foundation; either version 3 of the License, or
10
# (at your option) any later version.
11
#
12
# Koha is distributed in the hope that it will be useful, but
13
# WITHOUT ANY WARRANTY; without even the implied warranty of
14
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
# GNU General Public License for more details.
16
#
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>.
19
20
use strict;
21
use warnings;
22
use Carp;
23
use C4::Heading;
24
use C4::AuthoritiesMarc;
25
use C4::Linker::Default;    # Use Default for flipping
26
27
use base qw(C4::Linker);
28
29
sub new {
30
    my $class = shift;
31
    my $param = shift;
32
33
    my $self = $class->SUPER::new($param);
34
    $self->{'default_linker'} = C4::Linker::Default->new($param);
35
    bless $self, $class;
36
    return $self;
37
}
38
39
sub get_link {
40
    my $self        = shift;
41
    my $heading     = shift;
42
    my $search_form = $heading->search_form();
43
    my $authid;
44
    my $fuzzy = 0;
45
    
46
    #look for matching authorities
47
    my $authorities = $heading->authorities(1,9999999);    # $skipmetadata = true
48
	if ($#{$authorities} >= 0) {
49
		my %authcodes = (
50
      'PERSO_NAME','100',
51
			'CORPO_NAME', '110',
52
			'MEETI_NAME', '111',
53
			'UNIF_TITLE', '130',
54
			'CHRON_TERM', '148',
55
			'TOPIC_TERM', '150',
56
			'GEOGR_NAME', '151',
57
			'GENRE/FORM', '155',
58
			'GEN_SUBDIV', '180',
59
			'GEO_SUBDIV', '181',
60
			'CHRON_SUBD', '182',
61
			'FORM_SUBD',  '185'
62
		);
63
		my $fieldasstring = lc $heading->field()->as_string('abcdefghijklmnopqrstuvwxyz');
64
		# Remove subdivisions - they mess up our search here
65
		$fieldasstring =~ s/(generalsubdiv|formsubdiv|chronologicalsubdiv|geographicalsubdiv|\s|,|-|;)//g; 
66
		$fieldasstring =~ s/&/and/g; # Normalise to and
67
		for (my $n = 0; $n <= $#{$authorities}; $n = $n + 1) {
68
			my $auth = GetAuthority($authorities->[$n]->{'authid'});
69
			my $auth_field = $auth->field($authcodes{$heading->{'auth_type'}});
70
			my $authfieldstring = lc $auth->field($authcodes{$heading->{'auth_type'}})->as_string('abcdefghijklmnopqrstuvwxyz');
71
			$authfieldstring =~ s/(generalsubdiv|formsubdiv|chronologicalsubdiv|geographicalsubdiv|\s|,|-|;)//g;
72
			$authfieldstring =~ s/&/and/g;
73
			if ($fieldasstring eq $authfieldstring) {
74
				$authid = $authorities->[$n]->{'authid'};
75
				$n = $#{$authorities} + 1; # break out of the loop
76
			}
77
		}
78
		if (! defined $authid) {
79
			warn "No authority could be perfectly matched for " . $heading->field()->as_string('abcdefghijklmnopqrstuvwxyz') . "\n";
80
		        $fieldasstring =~ s/(\d|\.)//g; # Try alos removing full-stops and numbers
81
		        for (my $n = 0; $n <= $#{$authorities}; $n = $n + 1) {
82
                		my $auth = GetAuthority($authorities->[$n]->{'authid'});
83
		                my $auth_field = $auth->field($authcodes{$heading->{'auth_type'}});
84
		                my $authfieldstring = lc $auth->field($authcodes{$heading->{'auth_type'}})->as_string('abcdefghijklmnopqrstuvwxyz');
85
		                $authfieldstring =~ s/(generalsubdiv|formsubdiv|chronologicalsubdiv|geographicalsubdiv|\s|\d|,|-|;|\.)//g;
86
		                if ($fieldasstring eq $authfieldstring) {
87
				    warn "Fuzzy matching $fieldasstring with $authfieldstring\n";
88
		                    $authid = $authorities->[$n]->{'authid'};
89
				    $fuzzy = 1;
90
		                    $n = $#{$authorities} + 1; # break out of the loop
91
		                }
92
		        }
93
		}
94
		if (! defined $authid) {
95
			warn "No match found\n";
96
		}
97
	} else {
98
		warn "No match found\n";
99
	}
100
101
	$self->{'cache'}->{$search_form}->{'authid'} = $authid;
102
	$self->{'cache'}->{$search_form}->{'fuzzy'}  = $fuzzy;
103
104
    return $self->SUPER::_handle_auth_limit($authid), $fuzzy;
105
}
106
107
sub update_cache {
108
    my $self        = shift;
109
    my $heading     = shift;
110
    my $authid      = shift;
111
    $self->{'default_linker'}->update_cache( $heading, $authid );
112
}
113
114
sub flip_heading {
115
    my $self    = shift;
116
    my $heading = shift;
117
118
    return $self->{'default_linker'}->flip($heading);
119
}
120
121
1;
122
__END__
123
124
=head1 NAME
125
126
C4::Linker::BestMatch - match against the authority record that is identical or near identical (fuzzy)
127
128
=cut
(-)a/installer/data/mysql/sysprefs.sql (-1 / +1 lines)
Lines 221-227 INSERT INTO systempreferences ( `variable`, `value`, `options`, `explanation`, ` Link Here
221
('LibraryThingForLibrariesID','','','See:http://librarything.com/forlibraries/','free'),
221
('LibraryThingForLibrariesID','','','See:http://librarything.com/forlibraries/','free'),
222
('LibraryThingForLibrariesTabbedView','0','','Put LibraryThingForLibraries Content in Tabs.','YesNo'),
222
('LibraryThingForLibrariesTabbedView','0','','Put LibraryThingForLibraries Content in Tabs.','YesNo'),
223
('LinkerKeepStale','0',NULL,'If ON the authority linker will keep existing authority links for headings where it is unable to find a match.','YesNo'),
223
('LinkerKeepStale','0',NULL,'If ON the authority linker will keep existing authority links for headings where it is unable to find a match.','YesNo'),
224
('LinkerModule','Default','Default|FirstMatch|LastMatch','Chooses which linker module to use (see documentation).','Choice'),
224
('LinkerModule','Default','Default|FirstMatch|LastMatch|BestMatch','Chooses which linker module to use (see documentation).','Choice'),
225
('LinkerOptions','','','A pipe-separated list of options for the linker.','free'),
225
('LinkerOptions','','','A pipe-separated list of options for the linker.','free'),
226
('LinkerRelink','1',NULL,'If ON the authority linker will relink headings that have previously been linked every time it runs.','YesNo'),
226
('LinkerRelink','1',NULL,'If ON the authority linker will relink headings that have previously been linked every time it runs.','YesNo'),
227
('LocalCoverImages','0','1','Display local cover images on intranet details pages.','YesNo'),
227
('LocalCoverImages','0','1','Display local cover images on intranet details pages.','YesNo'),
(-)a/installer/data/mysql/updatedatabase.pl (-1 / +1 lines)
Lines 4756-4762 if (C4::Context->preference("Version") < TransformToNum($DBversion)) { Link Here
4756
$DBversion = "3.07.00.021";
4756
$DBversion = "3.07.00.021";
4757
if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
4757
if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
4758
    $dbh->do(
4758
    $dbh->do(
4759
    "INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES('LinkerModule','Default','Chooses which linker module to use (see documentation).','Default|FirstMatchLastMatch','Choice');"
4759
    "INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES('LinkerModule','Default','Chooses which linker module to use (see documentation).','Default|FirstMatch|LastMatch|BestMatch','Choice');"
4760
    );
4760
    );
4761
    $dbh->do(
4761
    $dbh->do(
4762
    "INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES('LinkerOptions','','A pipe-separated list of options for the linker.','','free');"
4762
    "INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES('LinkerOptions','','A pipe-separated list of options for the linker.','','free');"
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/authorities.pref (-1 / +1 lines)
Lines 58-63 Authorities: Link Here
58
                  Default: Default
58
                  Default: Default
59
                  FirstMatch: "First Match"
59
                  FirstMatch: "First Match"
60
                  LastMatch: "Last Match"
60
                  LastMatch: "Last Match"
61
                  BestMatch: "Best Match"
61
            - linker module for matching headings to authority records.
62
            - linker module for matching headings to authority records.
62
        -
63
        -
63
            - Set the following options for the authority linker
64
            - Set the following options for the authority linker
64
- 

Return to bug 16921