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 (+135 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
		my $fieldasstring = lc $heading->field()->as_string('abcdefghijklmnopqrstuvwxyz');
47
	  # Remove subdivisions - they mess up our search here
48
    $fieldasstring =~ s/(generalsubdiv|formsubdiv|chronologicalsubdiv|geographicalsubdiv|\s|,|-|;)//g; 
49
	  $fieldasstring =~ s/&/and/g; # Normalise to and
50
51
    if ( $self->{'cache'}->{$fieldasstring}->{'cached'} ) {
52
        $authid = $self->{'cache'}->{$fieldasstring}->{'authid'};
53
        $fuzzy  = $self->{'cache'}->{$fieldasstring}->{'fuzzy'};
54
				#warn "Cached result for $fieldasstring as $authid (Fuzzy: $fuzzy)";
55
    } else {
56
	    #look for matching authorities
57
			my $authorities = $heading->authorities(1,9999999);    # $skipmetadata = true
58
			if ($#{$authorities} >= 0) {
59
				my %authcodes = (
60
    		  'PERSO_NAME','100',
61
					'CORPO_NAME', '110',
62
					'MEETI_NAME', '111',
63
					'UNIF_TITLE', '130',
64
					'CHRON_TERM', '148',
65
					'TOPIC_TERM', '150',
66
					'GEOGR_NAME', '151',
67
					'GENRE/FORM', '155',
68
					'GEN_SUBDIV', '180',
69
					'GEO_SUBDIV', '181',
70
					'CHRON_SUBD', '182',
71
					'FORM_SUBD',  '185'
72
				);
73
				for (my $n = 0; $n <= $#{$authorities}; $n = $n + 1) {
74
					my $auth = GetAuthority($authorities->[$n]->{'authid'});
75
					my $auth_field = $auth->field($authcodes{$heading->{'auth_type'}});
76
					my $authfieldstring = lc $auth->field($authcodes{$heading->{'auth_type'}})->as_string('abcdefghijklmnopqrstuvwxyz');
77
					$authfieldstring =~ s/(generalsubdiv|formsubdiv|chronologicalsubdiv|geographicalsubdiv|\s|,|-|;)//g;
78
					$authfieldstring =~ s/&/and/g;
79
					if ($fieldasstring eq $authfieldstring) {
80
						$authid = $authorities->[$n]->{'authid'};
81
						$n = $#{$authorities} + 1; # break out of the loop
82
					}
83
				}
84
				if (! defined $authid) {
85
					warn "No authority could be perfectly matched for " . $heading->field()->as_string('abcdefghijklmnopqrstuvwxyz') . "\n";
86
		      $fieldasstring =~ s/(\d|\.)//g; # Try alos removing full-stops and numbers
87
		      for (my $n = 0; $n <= $#{$authorities}; $n = $n + 1) {
88
        		my $auth = GetAuthority($authorities->[$n]->{'authid'});
89
		        my $auth_field = $auth->field($authcodes{$heading->{'auth_type'}});
90
		      	my $authfieldstring = lc $auth->field($authcodes{$heading->{'auth_type'}})->as_string('abcdefghijklmnopqrstuvwxyz');
91
		        $authfieldstring =~ s/(generalsubdiv|formsubdiv|chronologicalsubdiv|geographicalsubdiv|\s|\d|,|-|;|\.)//g;
92
		        if ($fieldasstring eq $authfieldstring) {
93
					    warn "Fuzzy matching $fieldasstring with $authfieldstring\n";
94
	            $authid = $authorities->[$n]->{'authid'};
95
					    $fuzzy = 1;
96
		          $n = $#{$authorities} + 1; # break out of the loop
97
		        }
98
		      }
99
				}
100
				if (! defined $authid) {
101
					warn "No match found\n";
102
				}
103
			} else {
104
				warn "No match found\n";
105
			}
106
      $self->{'cache'}->{$fieldasstring}->{'cached'} = 1;
107
			$self->{'cache'}->{$fieldasstring}->{'authid'} = $authid;
108
			$self->{'cache'}->{$fieldasstring}->{'fuzzy'}  = $fuzzy;
109
		}
110
111
    return $self->SUPER::_handle_auth_limit($authid), $fuzzy;
112
}
113
114
sub update_cache {
115
    my $self        = shift;
116
    my $heading     = shift;
117
    my $authid      = shift;
118
    $self->{'default_linker'}->update_cache( $heading, $authid );
119
}
120
121
sub flip_heading {
122
    my $self    = shift;
123
    my $heading = shift;
124
125
    return $self->{'default_linker'}->flip($heading);
126
}
127
128
1;
129
__END__
130
131
=head1 NAME
132
133
C4::Linker::BestMatch - match against the authority record that is identical or near identical (fuzzy)
134
135
=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