Z39 Batch ML
authorBill Erickson <berick@esilibrary.com>
Thu, 31 Jan 2013 15:09:45 +0000 (10:09 -0500)
committerBill Erickson <berick@esilibrary.com>
Thu, 31 Jan 2013 15:09:45 +0000 (10:09 -0500)
Signed-off-by: Bill Erickson <berick@esilibrary.com>
Open-ILS/src/perlmods/lib/OpenILS/Application/Search/Z3950.pm

index d57cb9c..0036df0 100644 (file)
@@ -550,13 +550,26 @@ sub bucket_search_queue {
 
     $bre_ids = [ map {$_->{target_biblio_record_entry}} @$bre_ids ];
 
-    # build the Z39 queries for the source bib records
-
     $z_indexes = $e->search_config_z3950_index_field_map({id => $z_indexes});
 
     return OpenILS::Event->new('BAD_PARAMS', 
         note => q/No z_indexes/) unless @$z_indexes;
 
+    # build the Z39 queries for the source bib records
+
+    my $z_searches = compile_bucket_zsearch(
+        $e, $bre_ids, $z_sources, $z_indexes);
+
+    return $e->event unless $z_searches;
+
+    return $z_searches; # TODO
+}
+
+
+# creates a series of Z39.50 searchs based on the 
+# in-bucket records and the selected sources and indexes
+sub compile_bucket_zsearch {
+    my ($e, $bre_ids, $z_sources, $z_indexes) = @_;
 
     # pre-load the metabib_field's we'll need for this batch
 
@@ -568,7 +581,7 @@ sub bucket_search_queue {
         %mb_fields = map {$_->id => $_} @$field_objs;
     }
 
-    # pre-load the referenced z3950_attrs
+    # pre-load the z3950_attrs we'll need for this batch
 
     my %z3950_attrs;
     my @z3950_attrs = grep { $_->z3950_attr } @$z_indexes;
@@ -582,13 +595,12 @@ sub bucket_search_queue {
     my @z_index_attrs = grep { {defined $_->z3950_attr} } @$z_indexes;
     my @z_index_types = grep { {not defined $_->z3950_attr} } @$z_indexes;
 
-    # for each bib record, extract the indexed value for each of the 
-    # selected indexes.  
+    # for each bib record, extract the indexed value for the selected indexes.  
     my %z_searches;
 
     for my $bre_id (@$bre_ids) {
 
-        $z_searches{$bre_id} = {}; # TODO
+        $z_searches{$bre_id} = {};
 
         for my $z_index (@z_index_attrs, @z_index_types) {
 
@@ -626,7 +638,14 @@ sub bucket_search_queue {
                 # only applies to the z_source linked to the attr
 
                 $z_index_name = $z3950_attrs{$z_index->z3950_attr}->name;
-                push(@$z_source, $z3950_attrs{$z_index->z3950_attr}->source);
+                my $src = $z3950_attrs{$z_index->z3950_attr}->source;
+
+                if (grep { $_ eq $src } @$z_sources) {
+                    push(@$z_source, $src);
+                } else {
+                    $logger->warn("z39: z3950_attr '$z_index_name' for '$src'".
+                        " selected, but $src is not in the search list.  Skipping...");
+                }
 
             } else {
 
@@ -648,17 +667,16 @@ sub bucket_search_queue {
                 }
             }
 
-            # TODO
-            $z_searches{$bre_id}{$z_index->id} = {
-                z_source     => $z_source,
-                z_index_name => $z_index_name, 
-                bib_value    => $bre_val
-            };
-
+            if (@$z_source) {
+                $z_searches{$bre_id}{$z_index->id} = {
+                    z_source     => $z_source,
+                    z_index_name => $z_index_name, 
+                    bib_value    => $bre_val
+                };
+            }
         }
     }
 
-    # TODO
     return \%z_searches;
 }