# Suite 330, Boston, MA 02111-1307 USA
use strict;
+use warnings;
+
use C4::Context;
use MARC::Record;
use C4::Search;
use vars qw($VERSION);
-# set the version for version checking
-$VERSION = 3.00;
+BEGIN {
+ # set the version for version checking
+ $VERSION = 3.01;
+}
=head1 NAME
}
+my $matcher_description = $matcher->dump();
+
=back
=head1 FUNCTIONS
return $matchpoint_id;
}
+
+=head2 delete
+
+=over 4
+
+C4::Matcher->delete($id);
+
+=back
+
+Deletes the matcher of the specified ID
+from the database.
+
+=cut
+
+sub delete {
+ my $class = shift;
+ my $matcher_id = shift;
+
+ my $dbh = C4::Context->dbh;
+ my $sth = $dbh->prepare("DELETE FROM marc_matchers WHERE matcher_id = ?");
+ $sth->execute($matcher_id); # relying on cascading deletes to clean up everything
+}
+
=head2 threshold
=over 4
@_ ? $self->{'threshold'} = shift : $self->{'threshold'};
}
+=head2 _id
+
+=over 4
+
+$matcher->_id(123);
+my $id = $matcher->_id();
+
+=back
+
+Accessor method. Note that using this method
+to set the DB ID of the matcher should not be
+done outside of the editing CGI.
+
+=cut
+
+sub _id {
+ my $self = shift;
+ @_ ? $self->{'id'} = shift : $self->{'id'};
+}
+
=head2 code
=over 4
$self->add_matchpoint($index, $score, [
{ tag => $source_tag, subfields => $source_subfields,
- offset => $source_offset, length => $source_length,
+ offset => $source_offset, 'length' => $source_length,
norms => [ $source_normalizer ]
}
]);
$target_tag, $target_subfields, $target_offset, $target_length, $target_normalizer) = @_;
$self->add_required_check(
- [ { tag => $source_tag, subfields => $source_subfields, offset => $source_offset, length => $source_length,
+ [ { tag => $source_tag, subfields => $source_subfields, offset => $source_offset, 'length' => $source_length,
norms => [ $source_normalizer ] } ],
- [ { tag => $target_tag, subfields => $target_subfields, offset => $target_offset, length => $target_length,
+ [ { tag => $target_tag, subfields => $target_subfields, offset => $target_offset, 'length' => $target_length,
norms => [ $target_normalizer ] } ]
);
}
# build query
my $query = join(" or ", map { "$matchpoint->{'index'}=$_" } @source_keys);
# FIXME only searching biblio index at the moment
- my ($error, $searchresults) = SimpleSearch($query);
+ my ($error, $searchresults, $total_hits) = SimpleSearch($query, 0, $max_matches);
warn "search failed ($query) $error" if $error;
foreach my $matched (@$searchresults) {
}
+=head2 dump
+
+=over 4
+
+$description = $matcher->dump();
+
+=back
+
+Returns a reference to a structure containing all of the information
+in the matcher object. This is mainly a convenience method to
+aid setting up a HTML editing form.
+
+=cut
+
+sub dump {
+ my $self = shift;
+
+ my $result = {};
+
+ $result->{'matcher_id'} = $self->{'id'};
+ $result->{'code'} = $self->{'code'};
+ $result->{'description'} = $self->{'description'};
+
+ $result->{'matchpoints'} = [];
+ foreach my $matchpoint (@{ $self->{'matchpoints'} }) {
+ push @{ $result->{'matchpoints'} }, $matchpoint;
+ }
+ $result->{'matchchecks'} = [];
+ foreach my $matchcheck (@{ $self->{'required_checks'} }) {
+ push @{ $result->{'matchchecks'} }, $matchcheck;
+ }
+
+ return $result;
+}
+
sub _passes_required_checks {
my ($source_record, $target_blob, $matchchecks) = @_;
my $target_record = MARC::Record->new_from_usmarc($target_blob); # FIXME -- need to avoid parsing record twice
}
}
$key = _normalize($key);
+ if ($component->{'length'}){
+ if (length($key) > $component->{'length'}){
+ $key = _normalize(substr($key,$component->{'offset'},$component->{'length'}));
+ }
+ }
}
if ($i == 0) {
push @keys, $key if $key;
# FIXME - default normalizer
sub _normalize {
my $value = uc shift;
+ $value =~ s/[.;:,\]\[\)\(\/'"]//g;
$value =~ s/^\s+//;
- $value =~ s/^\s+$//;
+ #$value =~ s/^\s+$//;
+ $value =~ s/\s+$//;
$value =~ s/\s+/ /g;
- $value =~ s/[.;,\]\[\)\(\/"']//g;
+ #$value =~ s/[.;,\]\[\)\(\/"']//g;
return $value;
}
1;
+__END__
=head1 AUTHOR