{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 => {
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);
# 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
}
# 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
+ };
}
}