[OPEN-ILS-DEV] PATCH: Use ZOOM perl module instead of Net::Z3950

Dan Scott denials at gmail.com
Sun May 27 02:17:11 EDT 2007


The current Z3950 search relies on the Net::Z3950 Perl module, which
has been deprecated in favour of ZOOM (brought to you by the makers of
yaz, indexdata.dk). Currently, when you try to install Net::Z3950 from
CPAN or read its documentation, it very strongly warns you away from
using it in favour of ZOOM.

It turns out that the API for ZOOM is almost identical to Net::Z3950,
so this patch is relatively small. The major differences are the
reliance on search_pqf() to issue the search and the returned records
are 0-indexed rather than 1-indexed. We might be able to do more with
ZOOM's exceptions but I haven't looked into that. I have tested it
with Evergreen 1.1.5 and it works for cataloging resources from LC.
Unfortunately I do not have an OCLC account so I can't test
authenticated connections -- but from reading the ZOOM docs, it looks
like it should work.

One potential drawback to ZOOM is that it requires a version of yaz >=
2.1.50 (released 2007/02/03) as a prerequisite. Gentoo currently
offers a maximum of 2.1.42 (released 2006/12/17) even in its unstable
ebuild, so I had to build yaz from source. Depending on what level of
yaz other distributions package, we might want to leave this patch in
the queue for a while as we might be trading off one set of headaches
(Net::Z3950 is a deprecated package! EG is dumb for forcing me to
install a deprecated package on my system!) for another (ZOOM requires
yaz >= 2.1.50! EG is dumb for forcing me to install a package from
source on my system!).

Developer's Certificate of Origin 1.1

By making a contribution to this project, I certify that:
(a) The contribution was created in whole or in part by me and I have
the right to submit it under the open source license indicated in the
file; or
(b) The contribution is based upon previous work that, to the best of
my knowledge, is covered under an appropriate open source license and
I have the right under that license to submit that work with
modifications, whether created in whole or in part by me, under the
same open source license (unless I am permitted to submit under a
different license), as indicated in the file; or
(c) The contribution was provided directly to me by some other person
who certified (a), (b) or (c) and I have not modified it; and
(d) In the case of each of (a), (b), or (c), I understand and agree
that this project and the contribution are public and that a record of
the contribution (including all personal information I submit with it,
including my sign-off) is maintained indefinitely and may be
redistributed consistent with this project or the open source license
indicated in the file.

-- 
Dan Scott
Laurentian University
-------------- next part --------------
Index: Open-ILS/src/perlmods/OpenILS/Application/Search/Z3950.pm
===================================================================
RCS file: /cvs/ILS/Open-ILS/src/perlmods/OpenILS/Application/Search/Z3950.pm,v
retrieving revision 1.21
diff -c -r1.21 Z3950.pm
*** Open-ILS/src/perlmods/OpenILS/Application/Search/Z3950.pm	1 Feb 2007 16:35:15 -0000	1.21
--- Open-ILS/src/perlmods/OpenILS/Application/Search/Z3950.pm	27 May 2007 04:52:35 -0000
***************
*** 2,8 ****
  use strict; use warnings;
  use base qw/OpenSRF::Application/;
  
! use Net::Z3950;
  use MARC::Record;
  use MARC::File::XML;
  use Unicode::Normalize;
--- 2,8 ----
  use strict; use warnings;
  use base qw/OpenSRF::Application/;
  
! use ZOOM;
  use MARC::Record;
  use MARC::File::XML;
  use Unicode::Normalize;
***************
*** 163,169 ****
  	return $editor->event unless $editor->checkauth;
  	return $editor->event unless $editor->allowed('REMOTE_Z3950_QUERY');
  
! 	my $connection = new Net::Z3950::Connection(
  		$host, $port,
  		databaseName				=> $db, 
  		user							=> $username,
--- 163,169 ----
  	return $editor->event unless $editor->checkauth;
  	return $editor->event unless $editor->allowed('REMOTE_Z3950_QUERY');
  
! 	my $connection = new ZOOM::Connection(
  		$host, $port,
  		databaseName				=> $db, 
  		user							=> $username,
***************
*** 184,190 ****
  	$logger->info("z3950: query => $query");
  
  	try {
! 		$results = $connection->search( $query );
  	} catch Error with { $err = shift; };
  
  	return OpenILS::Event->new(
--- 184,190 ----
  	$logger->info("z3950: query => $query");
  
  	try {
! 		$results = $connection->search_pqf( $query );
  	} catch Error with { $err = shift; };
  
  	return OpenILS::Event->new(
***************
*** 220,230 ****
  	$logger->info("z3950: search returned $count hits");
  
  	my $tend = $limit + $offset;
- 	$offset++; # records start at 1
  
  	my $end = ($tend <= $count) ? $tend : $count;
  
! 	for($offset..$end) {
  
  		my $err;
  		my $mods;
--- 220,229 ----
  	$logger->info("z3950: search returned $count hits");
  
  	my $tend = $limit + $offset;
  
  	my $end = ($tend <= $count) ? $tend : $count;
  
! 	for($offset..$end - 1) {
  
  		my $err;
  		my $mods;
***************
*** 237,243 ****
  		try {
  
  			my $rec	= $results->record($_);
! 			$marc		= MARC::Record->new_from_usmarc($rec->rawdata());
  			$marcs	= entityize($marc->as_xml_record);
  			my $doc	= XML::LibXML->new->parse_string($marcs);
  			$marcxml = entityize( $doc->documentElement->toString );
--- 236,242 ----
  		try {
  
  			my $rec	= $results->record($_);
! 			$marc		= MARC::Record->new_from_usmarc($rec->raw());
  			$marcs	= entityize($marc->as_xml_record);
  			my $doc	= XML::LibXML->new->parse_string($marcs);
  			$marcxml = entityize( $doc->documentElement->toString );
***************
*** 287,293 ****
  #			$services{$service}->{attrs}->{$_}->{code} . " \"" . $$hash{$_} . "\" ";		
          $str .= 
              '@attr 1=' . $services{$service}->{attrs}->{$_}->{code} . # add the use attribute
!             ' @attr 4=' . $services{$service}->{attrs}->{$_}->{format} . # add teh structure attribute
              " \"" . $$hash{$_} . "\" "; # add the search term
  	}
  	return $str;
--- 286,292 ----
  #			$services{$service}->{attrs}->{$_}->{code} . " \"" . $$hash{$_} . "\" ";		
          $str .= 
              '@attr 1=' . $services{$service}->{attrs}->{$_}->{code} . # add the use attribute
!             ' @attr 4=' . $services{$service}->{attrs}->{$_}->{format} . # add the structure attribute
              " \"" . $$hash{$_} . "\" "; # add the search term
  	}
  	return $str;


More information about the Open-ils-dev mailing list