LP#1723977: Move no-LURIs test to be a peer of no-copies test
authorMike Rylander <miker@esilibrary.com>
Tue, 7 Nov 2017 16:09:07 +0000 (11:09 -0500)
committerChris Sharp <csharp@georgialibraries.org>
Mon, 12 Nov 2018 18:13:28 +0000 (13:13 -0500)
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>
Open-ILS/src/perlmods/lib/OpenILS/Application/Storage/Driver/Pg/QueryParser.pm

index 28624f0..de586c4 100644 (file)
@@ -1013,6 +1013,12 @@ sub toSQL {
         $$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