SELECT evergreen.upgrade_deps_block_check('1340', :eg_version);
--- INSERT-only table that catches dictionary updates to be reconciled
-CREATE UNLOGGED TABLE search.symspell_dictionary_updates (
- transaction_id BIGINT,
- keyword_count INT NOT NULL DEFAULT 0,
- title_count INT NOT NULL DEFAULT 0,
- author_count INT NOT NULL DEFAULT 0,
- subject_count INT NOT NULL DEFAULT 0,
- series_count INT NOT NULL DEFAULT 0,
- identifier_count INT NOT NULL DEFAULT 0,
-
- prefix_key TEXT NOT NULL,
-
- keyword_suggestions TEXT[],
- title_suggestions TEXT[],
- author_suggestions TEXT[],
- subject_suggestions TEXT[],
- series_suggestions TEXT[],
- identifier_suggestions TEXT[]
-);
-CREATE INDEX symspell_dictionary_updates_tid_idx ON search.symspell_dictionary_updates (transaction_id);
-
--- Function that collects this transactions additions to the unlogged update table
-CREATE OR REPLACE FUNCTION search.symspell_dictionary_reify () RETURNS SETOF search.symspell_dictionary AS $f$
- WITH new_rows AS (
- DELETE FROM search.symspell_dictionary_updates WHERE transaction_id = txid_current() RETURNING *
- ), computed_rows AS ( -- this collapses the rows deleted into the format we need for UPSERT
- SELECT SUM(keyword_count) AS keyword_count,
- SUM(title_count) AS title_count,
- SUM(author_count) AS author_count,
- SUM(subject_count) AS subject_count,
- SUM(series_count) AS series_count,
- SUM(identifier_count) AS identifier_count,
-
- prefix_key,
-
- ARRAY_REMOVE(ARRAY_AGG(DISTINCT keyword_suggestions[1]), NULL) AS keyword_suggestions,
- ARRAY_REMOVE(ARRAY_AGG(DISTINCT title_suggestions[1]), NULL) AS title_suggestions,
- ARRAY_REMOVE(ARRAY_AGG(DISTINCT author_suggestions[1]), NULL) AS author_suggestions,
- ARRAY_REMOVE(ARRAY_AGG(DISTINCT subject_suggestions[1]), NULL) AS subject_suggestions,
- ARRAY_REMOVE(ARRAY_AGG(DISTINCT series_suggestions[1]), NULL) AS series_suggestions,
- ARRAY_REMOVE(ARRAY_AGG(DISTINCT identifier_suggestions[1]), NULL) AS identifier_suggestions
- FROM new_rows
- GROUP BY prefix_key
- )
- INSERT INTO search.symspell_dictionary AS d SELECT * FROM computed_rows
- ON CONFLICT (prefix_key) DO UPDATE SET
- keyword_count = GREATEST(0, d.keyword_count + EXCLUDED.keyword_count),
- keyword_suggestions = evergreen.text_array_merge_unique(EXCLUDED.keyword_suggestions,d.keyword_suggestions),
-
- title_count = GREATEST(0, d.title_count + EXCLUDED.title_count),
- title_suggestions = evergreen.text_array_merge_unique(EXCLUDED.title_suggestions,d.title_suggestions),
-
- author_count = GREATEST(0, d.author_count + EXCLUDED.author_count),
- author_suggestions = evergreen.text_array_merge_unique(EXCLUDED.author_suggestions,d.author_suggestions),
-
- subject_count = GREATEST(0, d.subject_count + EXCLUDED.subject_count),
- subject_suggestions = evergreen.text_array_merge_unique(EXCLUDED.subject_suggestions,d.subject_suggestions),
-
- series_count = GREATEST(0, d.series_count + EXCLUDED.series_count),
- series_suggestions = evergreen.text_array_merge_unique(EXCLUDED.series_suggestions,d.series_suggestions),
-
- identifier_count = GREATEST(0, d.identifier_count + EXCLUDED.identifier_count),
- identifier_suggestions = evergreen.text_array_merge_unique(EXCLUDED.identifier_suggestions,d.identifier_suggestions)
- RETURNING *;
-$f$ LANGUAGE SQL;
-
--- simplified metabib.*_field_entry trigger that stages updates for reification in one go
-CREATE OR REPLACE FUNCTION search.symspell_maintain_entries () RETURNS TRIGGER AS $f$
-DECLARE
- search_class TEXT;
- new_value TEXT := NULL;
- old_value TEXT := NULL;
-BEGIN
- search_class := COALESCE(TG_ARGV[0], SPLIT_PART(TG_TABLE_NAME,'_',1));
-
- IF TG_OP IN ('INSERT', 'UPDATE') THEN
- new_value := NEW.value;
- END IF;
-
- IF TG_OP IN ('DELETE', 'UPDATE') THEN
- old_value := OLD.value;
- END IF;
-
- IF new_value = old_value THEN
- -- same, move along
- ELSE
- INSERT INTO search.symspell_dictionary_updates
- SELECT txid_current(), *
- FROM search.symspell_build_entries(
- new_value,
- search_class,
- old_value
- );
- END IF;
-
- RETURN NULL; -- always fired AFTER
-END;
-$f$ LANGUAGE PLPGSQL;
+-- -- INSERT-only table that catches dictionary updates to be reconciled
+-- CREATE UNLOGGED TABLE search.symspell_dictionary_updates (
+-- transaction_id BIGINT,
+-- keyword_count INT NOT NULL DEFAULT 0,
+-- title_count INT NOT NULL DEFAULT 0,
+-- author_count INT NOT NULL DEFAULT 0,
+-- subject_count INT NOT NULL DEFAULT 0,
+-- series_count INT NOT NULL DEFAULT 0,
+-- identifier_count INT NOT NULL DEFAULT 0,
+--
+-- prefix_key TEXT NOT NULL,
+--
+-- keyword_suggestions TEXT[],
+-- title_suggestions TEXT[],
+-- author_suggestions TEXT[],
+-- subject_suggestions TEXT[],
+-- series_suggestions TEXT[],
+-- identifier_suggestions TEXT[]
+-- );
+-- CREATE INDEX symspell_dictionary_updates_tid_idx ON search.symspell_dictionary_updates (transaction_id);
+
+-- -- Function that collects this transactions additions to the unlogged update table
+-- CREATE OR REPLACE FUNCTION search.symspell_dictionary_reify () RETURNS SETOF search.symspell_dictionary AS $f$
+-- WITH new_rows AS (
+-- DELETE FROM search.symspell_dictionary_updates WHERE transaction_id = txid_current() RETURNING *
+-- ), computed_rows AS ( -- this collapses the rows deleted into the format we need for UPSERT
+-- SELECT SUM(keyword_count) AS keyword_count,
+-- SUM(title_count) AS title_count,
+-- SUM(author_count) AS author_count,
+-- SUM(subject_count) AS subject_count,
+-- SUM(series_count) AS series_count,
+-- SUM(identifier_count) AS identifier_count,
+--
+-- prefix_key,
+--
+-- ARRAY_REMOVE(ARRAY_AGG(DISTINCT keyword_suggestions[1]), NULL) AS keyword_suggestions,
+-- ARRAY_REMOVE(ARRAY_AGG(DISTINCT title_suggestions[1]), NULL) AS title_suggestions,
+-- ARRAY_REMOVE(ARRAY_AGG(DISTINCT author_suggestions[1]), NULL) AS author_suggestions,
+-- ARRAY_REMOVE(ARRAY_AGG(DISTINCT subject_suggestions[1]), NULL) AS subject_suggestions,
+-- ARRAY_REMOVE(ARRAY_AGG(DISTINCT series_suggestions[1]), NULL) AS series_suggestions,
+-- ARRAY_REMOVE(ARRAY_AGG(DISTINCT identifier_suggestions[1]), NULL) AS identifier_suggestions
+-- FROM new_rows
+-- GROUP BY prefix_key
+-- )
+-- INSERT INTO search.symspell_dictionary AS d SELECT * FROM computed_rows
+-- ON CONFLICT (prefix_key) DO UPDATE SET
+-- keyword_count = GREATEST(0, d.keyword_count + EXCLUDED.keyword_count),
+-- keyword_suggestions = evergreen.text_array_merge_unique(EXCLUDED.keyword_suggestions,d.keyword_suggestions),
+--
+-- title_count = GREATEST(0, d.title_count + EXCLUDED.title_count),
+-- title_suggestions = evergreen.text_array_merge_unique(EXCLUDED.title_suggestions,d.title_suggestions),
+--
+-- author_count = GREATEST(0, d.author_count + EXCLUDED.author_count),
+-- author_suggestions = evergreen.text_array_merge_unique(EXCLUDED.author_suggestions,d.author_suggestions),
+--
+-- subject_count = GREATEST(0, d.subject_count + EXCLUDED.subject_count),
+-- subject_suggestions = evergreen.text_array_merge_unique(EXCLUDED.subject_suggestions,d.subject_suggestions),
+--
+-- series_count = GREATEST(0, d.series_count + EXCLUDED.series_count),
+-- series_suggestions = evergreen.text_array_merge_unique(EXCLUDED.series_suggestions,d.series_suggestions),
+--
+-- identifier_count = GREATEST(0, d.identifier_count + EXCLUDED.identifier_count),
+-- identifier_suggestions = evergreen.text_array_merge_unique(EXCLUDED.identifier_suggestions,d.identifier_suggestions)
+-- RETURNING *;
+-- $f$ LANGUAGE SQL;
+
+-- -- simplified metabib.*_field_entry trigger that stages updates for reification in one go
+-- CREATE OR REPLACE FUNCTION search.symspell_maintain_entries () RETURNS TRIGGER AS $f$
+-- DECLARE
+-- search_class TEXT;
+-- new_value TEXT := NULL;
+-- old_value TEXT := NULL;
+-- BEGIN
+-- search_class := COALESCE(TG_ARGV[0], SPLIT_PART(TG_TABLE_NAME,'_',1));
+--
+-- IF TG_OP IN ('INSERT', 'UPDATE') THEN
+-- new_value := NEW.value;
+-- END IF;
+--
+-- IF TG_OP IN ('DELETE', 'UPDATE') THEN
+-- old_value := OLD.value;
+-- END IF;
+--
+-- IF new_value = old_value THEN
+-- -- same, move along
+-- ELSE
+-- INSERT INTO search.symspell_dictionary_updates
+-- SELECT txid_current(), *
+-- FROM search.symspell_build_entries(
+-- new_value,
+-- search_class,
+-- old_value
+-- );
+-- END IF;
+--
+-- RETURN NULL; -- always fired AFTER
+-- END;
+-- $f$ LANGUAGE PLPGSQL;
CREATE OR REPLACE FUNCTION metabib.reingest_metabib_field_entries(
bib_id BIGINT,