my ($t_filter, $f_filter) = ('','');
my ($a_filter, $l_filter, $lf_filter) = ('','','');
+ my $use_rd = 0;
if (my $a = $args{audience}) {
$a = [$a] if (!ref($a));
my @aud = @$a;
$a_filter = ' AND rd.audience IN ('.join(',',map{'?'}@aud).')';
push @binds, @aud;
+ $use_rd = 1;
}
if (my $l = $args{language}) {
$l_filter = ' AND rd.item_lang IN ('.join(',',map{'?'}@lang).')';
push @binds, @lang;
+ $use_rd = 1;
}
if (my $f = $args{lit_form}) {
$lf_filter = ' AND rd.lit_form IN ('.join(',',map{'?'}@lit_form).')';
push @binds, @lit_form;
+ $use_rd = 1;
}
if (my $f = $args{item_form}) {
$f_filter = ' AND rd.item_form IN ('.join(',',map{'?'}@forms).')';
push @binds, @forms;
+ $use_rd = 1;
}
if (my $t = $args{item_type}) {
$t_filter = ' AND rd.item_type IN ('.join(',',map{'?'}@types).')';
push @binds, @types;
+ $use_rd = 1;
}
my @forms = split '', $f;
if (@types) {
$t_filter = ' AND rd.item_type IN ('.join(',',map{'?'}@types).')';
+ $use_rd = 1;
}
if (@forms) {
$f_filter .= ' AND rd.item_form IN ('.join(',',map{'?'}@forms).')';
+ $use_rd = 1;
}
push @binds, @types, @forms;
}
$sort = undef;
}
+ my $rd_join = $use_rd ? "$metabib_record_descriptor rd," : '';
+ my $rd_filter = $use_rd ? 'AND rd.record = f.record' : '';
if ($copies_visible) {
$select = <<" SQL";
$cs_table cs,
$cl_table cl,
$br_table br,
- $metabib_record_descriptor rd,
+ $rd_join
$descendants d
WHERE br.id = f.record
AND cn.record = f.record
- AND rd.record = f.record
AND cp.status = cs.id
AND cp.location = cl.id
AND br.deleted IS FALSE
AND cn.deleted IS FALSE
AND cp.deleted IS FALSE
+ $rd_filter
$has_vols
$has_copies
$copies_visible
$select = <<" SQL";
SELECT f.record, 1, 1, $rank
FROM $search_table f,
- $br_table br,
- $metabib_record_descriptor rd
+ $rd_join
+ $br_table br
WHERE br.id = f.record
- AND rd.record = f.record
AND br.deleted IS FALSE
+ $rd_filter
$t_filter
$f_filter
$a_filter