From: Bill Erickson Date: Thu, 31 Jan 2013 14:39:20 +0000 (-0500) Subject: Z39 Batch ML X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=1af2905c57fd5181e8511fbe5bd50b5a047e7275;p=evergreen%2Fequinox.git Z39 Batch ML Signed-off-by: Bill Erickson --- diff --git a/Open-ILS/src/perlmods/lib/OpenILS/Application/Search/Z3950.pm b/Open-ILS/src/perlmods/lib/OpenILS/Application/Search/Z3950.pm index 09e05ecd8a..d57cb9c4cb 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/Application/Search/Z3950.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/Application/Search/Z3950.pm @@ -495,7 +495,7 @@ __PACKAGE__->register_method( {desc => q/Authentication token/, type => 'string'}, {desc => q/Bucket ID/, type => 'number'}, {desc => q/Destination Queue name/, type => 'string'}, - {desc => q/Z39 Servers. List of czs.name/, type => 'array'}, + {desc => q/Z39 Sources. List of czs.name/, type => 'array'}, {desc => q/Z39 Index Maps. List of czifm.id/, type => 'array'} ], return => { @@ -527,7 +527,7 @@ sub bucket_search_queue { my $auth = shift; my $bucket_id = shift; my $qname = shift; - my $z_servers = shift; + my $z_sources = shift; my $z_indexes = shift; my $e = new_editor(authtoken => $auth); @@ -548,7 +548,7 @@ sub bucket_search_queue { # empty bucket return {queue_count => 0} unless @$bre_ids; - $bre_ids = [ map {$_->{id}} @$bre_ids ]; + $bre_ids = [ map {$_->{target_biblio_record_entry}} @$bre_ids ]; # build the Z39 queries for the source bib records @@ -579,49 +579,81 @@ sub bucket_search_queue { } # indexes with specific z3950_attr's take precedence - my @z_index_attrs = grep { {defined $_->z3959_attr} } @$z_indexes; - my @z_index_types = grep { {not defined $_->z3959_attr} } @$z_indexes; - - my %z_searches; + 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. + my %z_searches; for my $bre_id (@$bre_ids) { - $z_searches{$bre_id} = []; # TODO + $z_searches{$bre_id} = {}; # TODO for my $z_index (@z_index_attrs, @z_index_types) { my $bre_val; if ($z_index->record_attr) { + my $attrs = $U->get_bre_attrs($bre_id, $e); - $bre_val = $attrs->{$z_index->record_attr}->{code} - if $attrs->{$z_index->record_attr}; + $bre_val = $attrs->{$bre_id}{$z_index->record_attr}{code}; } else { # metabib_field my $fid = $z_index->metabib_field; - # now find the extacted value for this record + # the value for each field will be in the + # index class-specific table my $entry_query = sprintf( - 'search_%s_field_entry', $mb_fields{$fid}->field_class); + 'search_metabib_%s_field_entry', + $mb_fields{$fid}->field_class); - my $entry = $e->$entry_query({field => $fid, source => $bre_id}); + my $entry = $e->$entry_query( + {field => $fid, source => $bre_id})->[0]; $bre_val = $entry->value if $entry; } - push($z_searches{$bre_id}{$z_index->id}, [$z_index, $bre_val]); # TODO + # no value means no search + next unless $bre_val; + # determine which z3950 source to send this search field to + my $z_source = []; + my $z_index_name; + if ($z_index->z3950_attr) { + + # a specific z3950_attr means this search index + # 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); + + } else { + # when a generic attr type is used, it applies to all + # z-sources, except those for which a more specific + # z3950_attr has already been applied -# if ($bre_val) { -# if ($z_index->z3959_attr) { # source-specific -# $z_searches{$z_ -# } else { -# } -# } + $z_index_name = $z_index->z3950_attr_type; + + my @excluded; + for my $attr (values %z3950_attrs) { + push(@excluded, $attr->source) + if $attr->name eq $z_index_name; + } + + for my $src (@$z_sources) { + push(@$z_source, $src) unless + grep {$_ eq $src} @excluded; + } + } + + # TODO + $z_searches{$bre_id}{$z_index->id} = { + z_source => $z_source, + z_index_name => $z_index_name, + bib_value => $bre_val + }; } }