The correct place to test the no-LURIs condition is as a peer to the
no-copies test, when searching in staff mode. We therefore move that
test with this commit.
In addition, the bib attribute vector may be null, in the case of a
record with no bib source or LURI. When testing emptiness we need to
ask if the field IS NULL rather than just testing its contents.
Signed-off-by: Mike Rylander <mrylander@gmail.com>
Signed-off-by: Jason Boyer <JBoyer@library.in.gov>
$$flat_plan{with} .= "c_attr AS (SELECT (ARRAY_TO_STRING(ARRAY[$vis_test],'&'))::query_int AS vis_test FROM asset.patron_default_visibility_mask() x)";
$final_c_attr_test = 'EXISTS (SELECT 1 FROM asset.copy_vis_attr_cache WHERE record = m.source AND vis_attr_vector @@ c_attr.vis_test)';
+ if (!$pc_vis_test) { # staff search
+ $final_c_attr_test = '(' . $final_c_attr_test . " OR (" .
+ "NOT EXISTS (SELECT 1 FROM asset.copy_vis_attr_cache WHERE record = m.source) " .
+ "AND (bre.vis_attr_vector IS NULL OR NOT ( int4range(0,268435455,'[]') @> ANY(bre.vis_attr_vector) ))".
+ "))";
+ }
}
if ($self->find_modifier('staff')) { # staff search