3 -- check whether patch can be applied
4 SELECT evergreen.upgrade_deps_block_check('0839', :eg_version);
6 UPDATE config.metabib_field
8 xpath = $$//mods32:mods/mods32:titleInfo[mods32:title and starts-with(@type,'alternative')]$$,
9 browse_sort_xpath = $$*[local-name() != "nonSort"]$$,
12 field_class = 'title' AND name = 'alternative' ;
16 -- The following function only appears in the upgrade script and not the
17 -- baseline schema because it's not necessary in the latter (and it's a
18 -- temporary function). It just serves to do a hopefully cheaper, more
19 -- focused reingest just to hit the alternative title index.
21 -- This cribs from the guts of metabib.reingest_metabib_field_entries(),
22 -- and if it actually is a timesaver over a full reingest, then at some
23 -- point in the future it would be nice if we broke it out into a separate
24 -- function to make things like this easier.
26 CREATE OR REPLACE FUNCTION pg_temp.alternative_title_reingest( bib_id BIGINT ) RETURNS VOID AS $func$
28 ind_data metabib.field_entry_template%ROWTYPE;
29 mbe_row metabib.browse_entry%ROWTYPE;
31 b_skip_facet BOOL := false;
32 b_skip_browse BOOL := false;
33 b_skip_search BOOL := false;
37 SELECT INTO alt_title id FROM config.metabib_field WHERE field_class = 'title' AND name = 'alternative';
38 FOR ind_data IN SELECT * FROM biblio.extract_metabib_field_entry( bib_id ) WHERE field = alt_title LOOP
39 IF ind_data.field < 0 THEN
40 ind_data.field = -1 * ind_data.field;
43 IF ind_data.facet_field AND NOT b_skip_facet THEN
44 INSERT INTO metabib.facet_entry (field, source, value)
45 VALUES (ind_data.field, ind_data.source, ind_data.value);
48 IF ind_data.browse_field AND NOT b_skip_browse THEN
49 -- A caveat about this SELECT: this should take care of replacing
50 -- old mbe rows when data changes, but not if normalization (by
51 -- which I mean specifically the output of
52 -- evergreen.oils_tsearch2()) changes. It may or may not be
53 -- expensive to add a comparison of index_vector to index_vector
54 -- to the WHERE clause below.
56 value_prepped := metabib.browse_normalize(ind_data.value, ind_data.field);
57 SELECT INTO mbe_row * FROM metabib.browse_entry
58 WHERE value = value_prepped AND sort_value = ind_data.sort_value;
63 INSERT INTO metabib.browse_entry
64 ( value, sort_value ) VALUES
65 ( value_prepped, ind_data.sort_value );
67 mbe_id := CURRVAL('metabib.browse_entry_id_seq'::REGCLASS);
70 INSERT INTO metabib.browse_entry_def_map (entry, def, source, authority)
71 VALUES (mbe_id, ind_data.field, ind_data.source, ind_data.authority);
74 -- Avoid inserting duplicate rows, but retain granularity of being
75 -- able to search browse fields with "starts with" type operators
76 -- (for example, for titles of songs in music albums)
77 IF (ind_data.search_field OR ind_data.browse_field) AND NOT b_skip_search THEN
78 EXECUTE 'SELECT 1 FROM metabib.' || ind_data.field_class ||
79 '_field_entry WHERE field = $1 AND source = $2 AND value = $3'
80 INTO mbe_id USING ind_data.field, ind_data.source, ind_data.value;
81 -- RAISE NOTICE 'Search for an already matching row returned %', mbe_id;
82 IF mbe_id IS NULL THEN
84 INSERT INTO metabib.$$ || ind_data.field_class || $$_field_entry (field, source, value)
86 quote_literal(ind_data.field) || $$, $$ ||
87 quote_literal(ind_data.source) || $$, $$ ||
88 quote_literal(ind_data.value) ||
95 IF NOT b_skip_search THEN
96 PERFORM metabib.update_combined_index_vectors(bib_id);
101 $func$ LANGUAGE PLPGSQL;
103 \qecho This is a partial reingest of your bib records. It may take a while.
105 SELECT pg_temp.alternative_title_reingest(id) FROM biblio.record_entry WHERE NOT deleted;