[open-ils-commits] r10679 - trunk/Open-ILS/src/perlmods/OpenILS/Application/Search

svn at svn.open-ils.org svn at svn.open-ils.org
Mon Sep 22 08:36:59 EDT 2008


Author: erickson
Date: 2008-09-22 08:36:57 -0400 (Mon, 22 Sep 2008)
New Revision: 10679

Modified:
   trunk/Open-ILS/src/perlmods/OpenILS/Application/Search/Z3950.pm
Log:
porting the ability to search the local catalog as a Z3050 source

Modified: trunk/Open-ILS/src/perlmods/OpenILS/Application/Search/Z3950.pm
===================================================================
--- trunk/Open-ILS/src/perlmods/OpenILS/Application/Search/Z3950.pm	2008-09-22 08:14:08 UTC (rev 10678)
+++ trunk/Open-ILS/src/perlmods/OpenILS/Application/Search/Z3950.pm	2008-09-22 12:36:57 UTC (rev 10679)
@@ -15,9 +15,10 @@
 use OpenSRF::Utils::SettingsClient;
 use OpenILS::Application::AppUtils;
 use OpenSRF::Utils::Logger qw/$logger/;
-use OpenILS::Utils::Editor q/:funcs/;
+use OpenILS::Utils::CStoreEditor q/:funcs/;
 
 my $output	= "usmarc"; 
+my $U = 'OpenILS::Application::AppUtils'; 
 
 my $sclient;
 my %services;
@@ -84,7 +85,41 @@
 	my $e = new_editor(authtoken=>$auth);
 	return $e->event unless $e->checkauth;
 	return $e->event unless $e->allowed('REMOTE_Z3950_QUERY');
-	return $sclient->config_value('z3950', 'services');
+
+    if($e->can('search_config_z3950_source')) {
+
+        my $sources = $e->search_config_z3950_source( 
+            [ { name => { '!=' => undef } }, 
+            { flesh => 1, flesh_fields => { czs => ['attrs'] } }]  
+        ); 
+
+        my %hash = (); 
+        for my $s ( @$sources ) { 
+            $hash{ $s->name } = { 
+                name => $s->name, 
+                label => $s->label, 
+                host => $s->host, 
+                port => $s->port, 
+                db => $s->db, 
+                auth => $s->auth, 
+            }; 
+
+            for my $a ( @{ $s->attrs } ) { 
+                $hash{ $a->source }{attrs}{ $a->name } = { 
+                    name => $a->name, 
+                    label => $a->label, 
+                    code => $a->code, 
+                    format => $a->format, 
+                    source => $a->source, 
+                }; 
+            } 
+        } 
+
+        return \%hash; 
+
+    } else {
+        return $sclient->config_value('z3950', 'services');
+    }
 }
 
 
@@ -120,6 +155,7 @@
 
 	my @connections;
 	my @results;
+    my @services; 
 	for (my $i = 0; $i < @{$$args{service}}; $i++) {
 		my %tmp_args = %$args;
 		$tmp_args{service} = $$args{service}[$i];
@@ -128,19 +164,36 @@
 
 		$logger->debug("z3950: service: $tmp_args{service}, async: $tmp_args{async}");
 
-		$tmp_args{query} = compile_query('and', $tmp_args{service}, $tmp_args{search});
+        if ($tmp_args{service} eq 'native-evergreen-catalog') { 
+            my $method = $self->method_lookup('open-ils.search.biblio.zstyle'); 
+            $conn->respond( 
+                $self->method_lookup('open-ils.search.biblio.zstyle')->run($auth, \%tmp_args) 
+            ); 
 
-		my $res = do_service_search( $self, $conn, $auth, \%tmp_args );
+        } else { 
 
-		push @results, $res->{result};
-		push @connections, $res->{connection};
+            $tmp_args{query} = compile_query('and', $tmp_args{service}, $tmp_args{search}); 
+    
+            my $res = do_service_search( $self, $conn, $auth, \%tmp_args ); 
+    
+            if ($U->event_code($res)) { 
+                $conn->respond($res) if $U->event_code($res); 
 
+            } else { 
+                push @services, $tmp_args{service}; 
+                push @results, $res->{result}; 
+                push @connections, $res->{connection}; 
+            } 
+        }
+
 		$logger->debug("z3950: Result object: $results[$i], Connection object: $connections[$i]");
 	}
 
 	$logger->debug("z3950: Connections created");
 
+    return undef unless (@connections);
 	my @records;
+
 	while ((my $index = OpenILS::Utils::ZClient::event( \@connections )) != 0) {
 		my $ev = $connections[$index - 1]->last_event();
 		$logger->debug("z3950: Received event $ev");
@@ -171,6 +224,7 @@
 	$$args{host}	= $$info{host};
 	$$args{port}	= $$info{port};
 	$$args{db}		= $$info{db};
+    $logger->debug("z3950: do_search...");
 
 	return do_search( $self, $conn, $auth, $args );
 }
@@ -206,6 +260,8 @@
 	return $editor->event unless $editor->checkauth;
 	return $editor->event unless $editor->allowed('REMOTE_Z3950_QUERY');
 
+    $logger->info("z3950: connecting to server $host:$port:$db as $username");
+
 	my $connection = OpenILS::Utils::ZClient->new(
 		$host, $port,
 		databaseName				=> $db, 



More information about the open-ils-commits mailing list