ARRAY_TO_STRING(ARRAY_AGG(DISTINCT authority), $$,$$),
ARRAY_AGG(DISTINCT def)
FROM metabib.browse_author_entry_def_map map
- WHERE entry = rec.id
- AND (item_type IS NULL OR (
- source IN (
- SELECT id FROM metabib.record_attr rattr
- /* The seemingly superfluous rattr.id = map.source
- helps to ensure we're not filtering on every
- record with the selected mattype -- i.e.
- it makes this optional sub-filter faster */
- WHERE rattr.id = map.source AND attrs->'mattype' = item_type
- )
- ))
- AND def = ANY(fields);
+ WHERE entry = rec.id;
WHEN 'title' THEN
-- Gather aggregate data based on the MBE row we're looking at now, authority axis
ARRAY_TO_STRING(ARRAY_AGG(DISTINCT authority), $$,$$),
ARRAY_AGG(DISTINCT def)
FROM metabib.browse_title_entry_def_map map
- WHERE entry = rec.id
- AND (item_type IS NULL OR (
- source IN (
- SELECT id FROM metabib.record_attr rattr
- WHERE rattr.id = map.source AND attrs->'mattype' = item_type
- )
- ))
- AND def = ANY(fields);
+ WHERE entry = rec.id;
WHEN 'subject' THEN
--Is unauthorized, i.e., 4xx on an auth record?
ARRAY_TO_STRING(ARRAY_AGG(DISTINCT authority), $$,$$),
ARRAY_AGG(DISTINCT def)
FROM metabib.browse_subject_entry_def_map map
- WHERE entry = rec.id
- AND (item_type IS NULL OR (
- source IN (
- SELECT id FROM metabib.record_attr rattr
- WHERE rattr.id = map.source AND attrs->'mattype' = item_type
- )
- ))
- AND def = ANY(fields);
+ WHERE entry = rec.id;
WHEN 'series' THEN
--Is unauthorized, i.e., 4xx on an auth record?
ARRAY_TO_STRING(ARRAY_AGG(DISTINCT authority), $$,$$),
ARRAY_AGG(DISTINCT def)
FROM metabib.browse_series_entry_def_map map
- WHERE entry = rec.id
- AND (item_type IS NULL OR (
- source IN (
- SELECT id FROM metabib.record_attr rattr
- WHERE rattr.id = map.source AND attrs->'mattype' = item_type
- )
- ))
- AND def = ANY(fields);
+ WHERE entry = rec.id;
WHEN 'call_number' THEN
-- Gather aggregate data based on the MBE row we're looking at now, bib axis
ARRAY_TO_STRING(ARRAY_AGG(DISTINCT authority), $$,$$),
ARRAY_AGG(DISTINCT def)
FROM metabib.browse_call_number_entry_def_map
- WHERE entry = rec.id
- AND (item_type IS NULL OR (
- source IN (
- SELECT id FROM metabib.record_attr rattr
- WHERE rattr.id = map.source AND attrs->'mattype' = item_type
- )
- ))
- AND def = ANY(fields);
-
+ WHERE entry = rec.id;
ELSE
END CASE;
result_row.sources := 0;
result_row.asources := 0;
+ /** JBAS-1929 Remove references to any bib records that do not
+ match the requested item_type (mattype). */
+ IF item_type IS NOT NULL THEN
+
+
+ -- bib-linked bibs
+ IF ARRAY_UPPER(all_brecords, 1) IS NOT NULL THEN
+ -- RAISE NOTICE 'Checking bib links on %', all_brecords;
+
+ SELECT INTO all_brecords ARRAY_AGG(DISTINCT vec.source)
+ FROM metabib.record_attr_vector_list vec
+ JOIN config.coded_value_map ccvm
+ ON (
+ ccvm.ctype = 'mattype'
+ AND ccvm.code = item_type
+ AND ccvm.id = ANY (vec.vlist)
+ )
+ WHERE vec.source = ANY(all_brecords);
+
+ -- RAISE NOTICE 'Bib links trimmed to %', all_brecords;
+ END IF;
+
+ -- auth-linked bibs
+ IF ARRAY_UPPER(all_arecords, 1) IS NOT NULL THEN
+ -- RAISE NOTICE 'Checking auth links on %', all_arecords;
+
+ SELECT INTO all_arecords ARRAY_AGG(DISTINCT vec.source)
+ FROM metabib.record_attr_vector_list vec
+ JOIN config.coded_value_map ccvm
+ ON (
+ ccvm.ctype = 'mattype'
+ AND ccvm.code = item_type
+ AND ccvm.id = ANY (vec.vlist)
+ )
+ WHERE vec.source = ANY(all_arecords);
+
+ -- RAISE NOTICE 'Auth links trimmed to %', all_arecords;
+ END IF;
+
+ END IF;
+
-- Bib-linked vis checking
IF ARRAY_UPPER(all_brecords,1) IS NOT NULL THEN