[open-ils-commits] r8213 - in trunk/Open-ILS/src/perlmods/OpenILS: Application/Search Utils

svn at svn.open-ils.org svn at svn.open-ils.org
Fri Dec 14 21:42:54 EST 2007


Author: miker
Date: 2007-12-14 21:21:56 -0500 (Fri, 14 Dec 2007)
New Revision: 8213

Modified:
   trunk/Open-ILS/src/perlmods/OpenILS/Application/Search/Z3950.pm
   trunk/Open-ILS/src/perlmods/OpenILS/Utils/ZClient.pm
Log:
async and multi-target Z search .... yes, I am that indefferent to it

Modified: trunk/Open-ILS/src/perlmods/OpenILS/Application/Search/Z3950.pm
===================================================================
--- trunk/Open-ILS/src/perlmods/OpenILS/Application/Search/Z3950.pm	2007-12-13 17:40:19 UTC (rev 8212)
+++ trunk/Open-ILS/src/perlmods/OpenILS/Application/Search/Z3950.pm	2007-12-15 02:21:56 UTC (rev 8213)
@@ -109,10 +109,35 @@
 	my $auth			= shift;
 	my $args			= shift;
 
+	if (ref($$args{service}) =~ /ARRAY/o) {
+		$$args{service} = [$$args{service}];
+		$$args{username} = [$$args{username}];
+		$$args{password} = [$$args{password}];
+	}
+
+	$$args{async} = 1;
+
 	$$args{query} = 
 		compile_query('and', $$args{service}, $$args{search});
 
-	return $self->do_service_search( $conn, $auth, $args );
+	my @results;
+	for (var $i = 0; $i < @{$$args{service}}; i++) {
+		my %tmp_args = %$args;
+		$tmp_args{service} = $$args{service}[$i];
+		$tmp_args{username} = $$args{username}[$i];
+		$tmp_args{password} = $$args{password}[$i];
+		$results[$i] = $self->do_service_search( $conn, $auth, \%tmp_args );
+	}
+
+	my @records;
+	while ((my $index = OpenILS::Utils::ZClient::event( \@results )) != 0) {
+		my $ev = $results[$index - 1]->last_event();
+		if ($ev == OpenILS::Utils::ZClient::Event::END) {
+			my $munged = process_results( $results[$index - 1], $limit, $offset );
+			$$munged{service} = $$args{service}[$index];
+			$conn->respond($munged);
+		}
+	}
 }
 
 
@@ -152,6 +177,7 @@
 	my $port		= $$args{port} or return undef;
 	my $db		= $$args{db}	or return undef;
 	my $query	= $$args{query} or return undef;
+	my $async	= $$args{async} || 0;
 
 	my $limit	= $$args{limit} || 10;
 	my $offset	= $$args{offset} || 0;
@@ -167,6 +193,7 @@
 		$host, $port,
 		databaseName				=> $db, 
 		user							=> $username,
+		async							=> $async,
 		password						=> $password,
 		preferredRecordSyntax	=> $output, 
 	);
@@ -195,6 +222,8 @@
 
 	$logger->info("z3950: search [$query] took ".(time - $start)." seconds");
 
+	return $result if ($async);
+
 	my $munged = process_results($results, $limit, $offset);
 	$munged->{query} = $query;
 

Modified: trunk/Open-ILS/src/perlmods/OpenILS/Utils/ZClient.pm
===================================================================
--- trunk/Open-ILS/src/perlmods/OpenILS/Utils/ZClient.pm	2007-12-13 17:40:19 UTC (rev 8212)
+++ trunk/Open-ILS/src/perlmods/OpenILS/Utils/ZClient.pm	2007-12-15 02:21:56 UTC (rev 8213)
@@ -45,6 +45,20 @@
 	return OpenILS::Utils::ZClient::ResultSet->new( $r );
 }
 
+sub event {
+	my $list = shift;
+	if ($imp_class eq 'Net::Z3950') {
+		if (defined $$list[0]{_async_index}) {	
+			return 0 if ($$list[0]{_async_index} == @$list);
+			return ++$$list[0]{_async_index};
+		} else {
+			return $$list[0]{_async_index} = 1;
+		}
+	}
+
+	return ZOOM::event([map { ($_->{result}) } @$list]);
+}
+
 *{__PACKAGE__ . '::search_pqf'} = \&search; 
 
 sub AUTOLOAD {
@@ -84,6 +98,12 @@
 	return  OpenILS::Utils::ZClient::Record->new( $r );
 }
 
+sub last_event {
+	my $self = shift;
+	return OpenILS::Utils::ZClient::Event::EVENT_END if ($imp_class eq 'Net::Z3950');
+	$self->{result}->last_event();
+}
+
 sub AUTOLOAD {
 	my $self = shift;
 
@@ -129,6 +149,20 @@
 	return $self->{record}->$method( @_ );
 }
 
+#-------------------------------------------------------------------------------
+package OpenILS::Utils::ZClient::Event;
 
+sub NONE { 0 }
+sub CONNECT { 1 }
+sub SEND_DATA { 2 }
+sub RECV_DATA { 3 }
+sub TIMEOUT { 4 }
+sub UNKNOWN { 5 }
+sub SEND_APDU { 6 }
+sub RECV_APDU { 7 }
+sub RECV_RECORD { 8 }
+sub RECV_SEARCH { 9 }
+sub END { 10 }
+
 1;
 



More information about the open-ils-commits mailing list