It is clear that some of the issues are related to our data. This was done after the authorities and bibs were reingested in the 2.5 upgrade. One thing I don't understand is why the subfield 0 appears. No matter how bad our data is, it seems that should never show up.
I'm sure we have some records with "Christianity and Literature" that has an errant period that prevented the bibliographic subject entry from linking to the authority.
1) run Mike's script
DO $$
DECLARE
auth authority.record_entry%ROWTYPE;
ashs authority.simple_heading%ROWTYPE;
mbe_row metabib.browse_entry%ROWTYPE;
mbe_id BIGINT;
ash_id BIGINT;
BEGIN
DELETE FROM authority.simple_heading;
FOR auth IN SELECT * FROM authority.record_entry WHERE NOT DELETED LOOP
FOR ashs IN SELECT * FROM authority.simple_heading_set(auth.marc) LOOP
INSERT INTO authority.simple_heading (record,atag,value,sort_value)
VALUES (ashs.record, ashs.atag, ashs.value, ashs.sort_value);
ash_id := CURRVAL('authority.simple_heading_id_seq'::REGCLASS);
SELECT INTO mbe_row * FROM metabib.browse_entry
WHERE value = ashs.value AND sort_value = ashs.sort_value;
IF FOUND THEN
mbe_id := mbe_row.id;
ELSE
INSERT INTO metabib.browse_entry
( value, sort_value ) VALUES
( ashs.value, ashs.sort_value );
mbe_id := CURRVAL('metabib.browse_entry_id_seq'::REGCLASS);
END IF;
INSERT INTO metabib.browse_entry_simple_heading_map (entry,simple_heading) VALUES (mbe_id,ash_id);
END LOOP;
END LOOP;
END;
$$;
2) remove orphaned browse data
DELETE FROM authority.simple_heading;
DELETE FROM metabib.browse_entry WHERE id IN ( SELECT e.id FROM metabib.browse_entry e LEFT JOIN metabib.browse_entry_def_map b ON (b.entry = e.id) LEFT JOIN metabib.browse_entry_simple_heading_map a ON (b.entry = e.id) WHERE b.id IS NULL AND a.id IS NULL
3) reingest the authorities with this
\t
\o reingest.auth.sql
SELECT 'UPDATE config.internal_flag SET enabled = ''t'' WHERE name = ''ingest.reingest.force_on_same_marc'';';
SELECT 'UPDATE authority.record_entry SET id = id WHERE id = ' || id || ';' FROM authority.record_entry WHERE NOT deleted; SELECT 'UPDATE config.internal_flag SET enabled = ''' || (SELECT enabled FROM config.internal_flag WHERE name = 'ingest.reingest.force_on_same_marc') || ''' WHERE name = ''ingest.reingest.force_on_same_marc'';';
\o
It is clear that some of the issues are related to our data. This was done after the authorities and bibs were reingested in the 2.5 upgrade. One thing I don't understand is why the subfield 0 appears. No matter how bad our data is, it seems that should never show up.
http:// bark.cwmars. org/eg/ opac/browse? blimit= 25&qtype= subject& bterm=christian ity+and+ literature& locg=1
Specifically, this entry appears
christianity and literature cwmars 32948
I'm sure we have some records with "Christianity and Literature" that has an errant period that prevented the bibliographic subject entry from linking to the authority.
1) run Mike's script
DO $$ record_ entry%ROWTYPE; simple_ heading% ROWTYPE; browse_ entry%ROWTYPE; simple_ heading; record_ entry WHERE NOT DELETED LOOP simple_ heading_ set(auth. marc) LOOP simple_ heading (record, atag,value, sort_value) 'authority. simple_ heading_ id_seq' ::REGCLASS) ; browse_ entry browse_ entry 'metabib. browse_ entry_id_ seq'::REGCLASS) ; browse_ entry_simple_ heading_ map (entry, simple_ heading) VALUES (mbe_id,ash_id);
DECLARE
auth authority.
ashs authority.
mbe_row metabib.
mbe_id BIGINT;
ash_id BIGINT;
BEGIN
DELETE FROM authority.
FOR auth IN SELECT * FROM authority.
FOR ashs IN SELECT * FROM authority.
INSERT INTO authority.
VALUES (ashs.record, ashs.atag, ashs.value, ashs.sort_value);
ash_id := CURRVAL(
SELECT INTO mbe_row * FROM metabib.
WHERE value = ashs.value AND sort_value = ashs.sort_value;
IF FOUND THEN
mbe_id := mbe_row.id;
ELSE
INSERT INTO metabib.
( value, sort_value ) VALUES
( ashs.value, ashs.sort_value );
mbe_id := CURRVAL(
END IF;
INSERT INTO metabib.
END LOOP;
END LOOP;
END;
$$;
2) remove orphaned browse data
DELETE FROM authority. simple_ heading;
DELETE FROM metabib. browse_ entry WHERE id IN ( SELECT e.id FROM metabib. browse_ entry e LEFT JOIN metabib. browse_ entry_def_ map b ON (b.entry = e.id) LEFT JOIN metabib. browse_ entry_simple_ heading_ map a ON (b.entry = e.id) WHERE b.id IS NULL AND a.id IS NULL
3) reingest the authorities with this
\t internal_ flag SET enabled = ''t'' WHERE name = ''ingest. reingest. force_on_ same_marc' ';'; record_ entry SET id = id WHERE id = ' || id || ';' FROM authority. record_ entry WHERE NOT deleted; SELECT 'UPDATE config. internal_ flag SET enabled = ''' || (SELECT enabled FROM config. internal_ flag WHERE name = 'ingest. reingest. force_on_ same_marc' ) || ''' WHERE name = ''ingest. reingest. force_on_ same_marc' ';';
\o reingest.auth.sql
SELECT 'UPDATE config.
SELECT 'UPDATE authority.
\o
Ran the file “reingest.auth.sql”