Comment 3 for bug 1307629

Revision history for this message
Tim Spindler (tspindler-cwmars) wrote :

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=christianity+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 $$
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

Ran the file “reingest.auth.sql”