[open-ils-commits] r8221 - in trunk/Open-ILS/src/perlmods/OpenILS:
Application/Search Utils
svn at svn.open-ils.org
svn at svn.open-ils.org
Sat Dec 15 21:08:11 EST 2007
Author: miker
Date: 2007-12-15 20:47:04 -0500 (Sat, 15 Dec 2007)
New Revision: 8221
Modified:
trunk/Open-ILS/src/perlmods/OpenILS/Application/Search/Z3950.pm
trunk/Open-ILS/src/perlmods/OpenILS/Utils/ZClient.pm
Log:
multi-target Z39.50 searches -- just supply an array for all of username, password and service
Modified: trunk/Open-ILS/src/perlmods/OpenILS/Application/Search/Z3950.pm
===================================================================
--- trunk/Open-ILS/src/perlmods/OpenILS/Application/Search/Z3950.pm 2007-12-15 16:08:52 UTC (rev 8220)
+++ trunk/Open-ILS/src/perlmods/OpenILS/Application/Search/Z3950.pm 2007-12-16 01:47:04 UTC (rev 8221)
@@ -27,6 +27,7 @@
__PACKAGE__->register_method(
method => 'do_class_search',
api_name => 'open-ils.search.z3950.search_class',
+ stream => 1,
signature => q/
Performs a class based Z search. The classes available
are defined by the 'attr' fields in the config for the
@@ -117,27 +118,40 @@
$$args{async} = 1;
- $$args{query} =
- compile_query('and', $$args{service}, $$args{search});
-
+ my @connections;
my @results;
for (my $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 );
+
+ $logger->debug("z3950: service: $tmp_args{service}, async: $tmp_args{async}");
+
+ $tmp_args{query} = compile_query('and', $tmp_args{service}, $tmp_args{search});
+
+ my $res = $self->do_service_search( $conn, $auth, \%tmp_args );
+
+ push @results, $res->{result};
+ push @connections, $res->{connection};
+
+ $logger->debug("z3950: Result object: $results[$i], Connection object: $connections[$i]");
}
+ $logger->debug("z3950: Connections created");
+
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], ($$args{limit} || 10), ($$args{offset} || 0) );
- $$munged{service} = $$args{service}[$index];
+ while ((my $index = OpenILS::Utils::ZClient::event( \@connections )) != 0) {
+ my $ev = $connections[$index - 1]->last_event();
+ $logger->debug("z3950: Received event $ev");
+ if ($ev == OpenILS::Utils::ZClient::EVENT_END()) {
+ my $munged = process_results( $results[$index - 1], $$args{limit}, $$args{offset} );
+ $$munged{service} = $$args{service}[$index - 1];
$conn->respond($munged);
}
}
+
+ $logger->debug("z3950: Search Complete");
}
@@ -193,8 +207,8 @@
$host, $port,
databaseName => $db,
user => $username,
+ password => $password,
async => $async,
- password => $password,
preferredRecordSyntax => $output,
);
@@ -222,7 +236,7 @@
$logger->info("z3950: search [$query] took ".(time - $start)." seconds");
- return $results if ($async);
+ return {result => $results, connection => $connection} if ($async);
my $munged = process_results($results, $limit, $offset);
$munged->{query} = $query;
@@ -237,8 +251,8 @@
# -------------------------------------------------------------------
sub process_results {
my $results = shift;
- my $limit = shift;
- my $offset = shift;
+ my $limit = shift || 10;
+ my $offset = shift || 0;
$results->option(elementSetName => "FI"); # full records with no holdings
Modified: trunk/Open-ILS/src/perlmods/OpenILS/Utils/ZClient.pm
===================================================================
--- trunk/Open-ILS/src/perlmods/OpenILS/Utils/ZClient.pm 2007-12-15 16:08:52 UTC (rev 8220)
+++ trunk/Open-ILS/src/perlmods/OpenILS/Utils/ZClient.pm 2007-12-16 01:47:04 UTC (rev 8221)
@@ -3,6 +3,18 @@
use overload 'bool' => sub { return $_[0]->{connection} ? 1 : 0 };
+sub EVENT_NONE { 0 }
+sub EVENT_CONNECT { 1 }
+sub EVENT_SEND_DATA { 2 }
+sub EVENT_RECV_DATA { 3 }
+sub EVENT_TIMEOUT { 4 }
+sub EVENT_UNKNOWN { 5 }
+sub EVENT_SEND_APDU { 6 }
+sub EVENT_RECV_APDU { 7 }
+sub EVENT_RECV_RECORD { 8 }
+sub EVENT_RECV_SEARCH { 9 }
+sub EVENT_END { 10 }
+
our $conn_class = 'ZOOM::Connection';
our $imp_class = 'ZOOM';
our $AUTOLOAD;
@@ -56,7 +68,7 @@
}
}
- return ZOOM::event([map { ($_->{result}) } @$list]);
+ return ZOOM::event([map { ($_->{connection}) } @$list]);
}
*{__PACKAGE__ . '::search_pqf'} = \&search;
@@ -100,7 +112,7 @@
sub last_event {
my $self = shift;
- return OpenILS::Utils::ZClient::Event::EVENT_END if ($imp_class eq 'Net::Z3950');
+ return OpenILS::Utils::ZClient::EVENT_END() if ($imp_class eq 'Net::Z3950');
$self->{result}->last_event();
}
@@ -149,20 +161,5 @@
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