use OpenSRF::MultiSession;
use OpenILS::Utils::ModsParser;
use OpenSRF::Utils::SettingsClient;
+use OpenSRF::Utils::JSON;
use OpenILS::Application::AppUtils;
use OpenSRF::Utils::Logger qw/$logger/;
use OpenILS::Utils::CStoreEditor q/:funcs/;
my $res = {};
my $count = $$res{count} = $results->size;
- $logger->info("z3950: search returned $count hits");
+ $logger->info("z3950: '$service' search returned $count hits");
my $tend = $limit + $offset;
q/Object containing status information about the on-going search
and queue operation.
{
- bre_count : $num, -- number of bibs to search against
+ bre_count : $num, -- number of bibs to search against
search_count : $num,
search_complete : $num,
queue_count : $num
# there will be one response per z-source
for my $resp (@{$req->{response}}) {
- next unless $resp->content;
-
- my $result = $resp->content;
$response->{search_complete}++;
+ $logger->info("z3950 got bucket response for request " .
+ OpenSRF::Utils::JSON->perl2JSON($req->{params}));
+
+ my $result = $resp->content or next;
my $service = $result->{service};
for my $rec (@{$result->{records}}) {
my $multi_ses = OpenSRF::MultiSession->new(
app => 'open-ils.search',
cap => $max_parallel,
+ timeout => 120,
success_handler => $handle_search_result
);
- # fire a Z39 search for each distinct combination of z-sources
+ # compile and send the z3950-compatible search blobs
+ my @searches;
for my $bre_id (keys %$z_searches) {
- # build a search blob for each distinct combination of z-sources
- my @searches;
+ # one search blob per distinct set of Z sources for this record
+ my @rec_searches;
for my $z_index (keys %{$z_searches->{$bre_id}}) {
my $search = $z_searches->{$bre_id}{$z_index};
+ $logger->info("z39 search piece [$bre_id]: " . $search->{z_index_name});
+
my ($blob) = grep {
# array compare, weee
@{$_->{service}} ~~ @{$search->{z_source}}
- } @searches;
+ } @rec_searches;
if ($blob) {
+
$blob->{search}{$search->{z_index_name}} =
$search->{bib_value};
+
} else {
+
$blob = {
service => $search->{z_source},
- $search->{z_index_name} => $search->{bib_value},
+ search => {
+ $search->{z_index_name} => $search->{bib_value}
+ },
limit => $search_limit,
offset => 0
};
- push(@searches, $blob);
+ push(@rec_searches, $blob);
}
-
- # search count is incremented by one for every
- # service we sent a search blob to
- $response->{search_count}++ for @{$blob->{service}};
}
- $multi_ses->request(
- 'open-ils.search.z3950.search_class',
- $e->authtoken, $_) for @searches;
+ push(@searches, $_) for @rec_searches;
}
+
+
+ # multi-session blocks new requests once it reaches max parallel,
+ # so we need to calculate the number of searches up front
+ # for accurate reporting
+ $response->{search_count} += scalar(@{$_->{service}}) for @searches;
$conn->respond($response); # searches in flight
- $multi_ses->session_wait(1);
+ for my $search (@searches) {
+
+ $logger->info("z39 firing bucket search " .
+ OpenSRF::Utils::JSON->perl2JSON($search));
+
+ # toss it onto the multi-pile
+ my $req = $multi_ses->request(
+ 'open-ils.search.z3950.search_class', $e->authtoken, $search);
+ }
+
+ $multi_ses->session_wait(1);
$response->{queue} = $queue;
$conn->respond($response);
}