From: Galen Charlton Date: Tue, 25 May 2021 14:33:28 +0000 (-0400) Subject: LP#1923225: stamp DB update X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=d1eab89b0ce9fe2e57d2c40b1d16cf25c45a1287;p=Evergreen.git LP#1923225: stamp DB update Signed-off-by: Galen Charlton --- diff --git a/Open-ILS/src/sql/Pg/002.schema.config.sql b/Open-ILS/src/sql/Pg/002.schema.config.sql index 9ecead8a6a..bec8d91d64 100644 --- a/Open-ILS/src/sql/Pg/002.schema.config.sql +++ b/Open-ILS/src/sql/Pg/002.schema.config.sql @@ -92,7 +92,7 @@ CREATE TRIGGER no_overlapping_deps BEFORE INSERT OR UPDATE ON config.db_patch_dependencies FOR EACH ROW EXECUTE PROCEDURE evergreen.array_overlap_check ('deprecates'); -INSERT INTO config.upgrade_log (version, applied_to) VALUES ('1261', :eg_version); -- berick/ehardy/sandbergja +INSERT INTO config.upgrade_log (version, applied_to) VALUES ('1262', :eg_version); -- jeff/gmcharlt/mmorgan CREATE TABLE config.bib_source ( id SERIAL PRIMARY KEY, diff --git a/Open-ILS/src/sql/Pg/upgrade/1262.schema.search_highlight_escape_html.sql b/Open-ILS/src/sql/Pg/upgrade/1262.schema.search_highlight_escape_html.sql new file mode 100644 index 0000000000..fbb0468029 --- /dev/null +++ b/Open-ILS/src/sql/Pg/upgrade/1262.schema.search_highlight_escape_html.sql @@ -0,0 +1,118 @@ +BEGIN; + +SELECT evergreen.upgrade_deps_block_check('1262', :eg_version); + +CREATE OR REPLACE FUNCTION search.highlight_display_fields_impl( + rid BIGINT, + tsq TEXT, + field_list INT[] DEFAULT '{}'::INT[], + css_class TEXT DEFAULT 'oils_SH', + hl_all BOOL DEFAULT TRUE, + minwords INT DEFAULT 5, + maxwords INT DEFAULT 25, + shortwords INT DEFAULT 0, + maxfrags INT DEFAULT 0, + delimiter TEXT DEFAULT ' ... ' +) RETURNS SETOF search.highlight_result AS $f$ +DECLARE + opts TEXT := ''; + v_css_class TEXT := css_class; + v_delimiter TEXT := delimiter; + v_field_list INT[] := field_list; + hl_query TEXT; +BEGIN + IF v_delimiter LIKE $$%'%$$ OR v_delimiter LIKE '%"%' THEN --" + v_delimiter := ' ... '; + END IF; + + IF NOT hl_all THEN + opts := opts || 'MinWords=' || minwords; + opts := opts || ', MaxWords=' || maxwords; + opts := opts || ', ShortWords=' || shortwords; + opts := opts || ', MaxFragments=' || maxfrags; + opts := opts || ', FragmentDelimiter="' || delimiter || '"'; + ELSE + opts := opts || 'HighlightAll=TRUE'; + END IF; + + IF v_css_class LIKE $$%'%$$ OR v_css_class LIKE '%"%' THEN -- " + v_css_class := 'oils_SH'; + END IF; + + opts := opts || $$, StopSel=, StartSel=""$xx$ -- "' + ) AS highlight + FROM metabib.display_entry de + JOIN config.metabib_field mf ON (mf.id = de.field) + JOIN search.best_tsconfig t ON (t.id = de.field) + WHERE de.source = $2 + AND field = ANY ($3) + ORDER BY de.id;$$; + + RETURN QUERY EXECUTE hl_query USING opts, rid, v_field_list; +END; +$f$ LANGUAGE PLPGSQL; + +CREATE OR REPLACE FUNCTION search.highlight_display_fields( + rid BIGINT, + tsq_map TEXT, -- { '(a | b) & c' => '1,2,3,4', ...} + css_class TEXT DEFAULT 'oils_SH', + hl_all BOOL DEFAULT TRUE, + minwords INT DEFAULT 5, + maxwords INT DEFAULT 25, + shortwords INT DEFAULT 0, + maxfrags INT DEFAULT 0, + delimiter TEXT DEFAULT ' ... ' +) RETURNS SETOF search.highlight_result AS $f$ +DECLARE + tsq_hstore TEXT; + tsq TEXT; + fields TEXT; + afields INT[]; + seen INT[]; +BEGIN + IF (tsq_map ILIKE 'hstore%') THEN + EXECUTE 'SELECT ' || tsq_map INTO tsq_hstore; + ELSE + tsq_hstore := tsq_map::HSTORE; + END IF; + + FOR tsq, fields IN SELECT key, value FROM each(tsq_hstore::HSTORE) LOOP + SELECT ARRAY_AGG(unnest::INT) INTO afields + FROM unnest(regexp_split_to_array(fields,',')); + seen := seen || afields; + + RETURN QUERY + SELECT * FROM search.highlight_display_fields_impl( + rid, tsq, afields, css_class, hl_all,minwords, + maxwords, shortwords, maxfrags, delimiter + ); + END LOOP; + + RETURN QUERY + SELECT id, + source, + field, + evergreen.escape_for_html(value) AS value, + evergreen.escape_for_html(value) AS highlight + FROM metabib.display_entry + WHERE source = rid + AND NOT (field = ANY (seen)); +END; +$f$ LANGUAGE PLPGSQL ROWS 10; + +COMMIT; diff --git a/Open-ILS/src/sql/Pg/upgrade/XXXX.schema.search_highlight_escape_html.sql b/Open-ILS/src/sql/Pg/upgrade/XXXX.schema.search_highlight_escape_html.sql deleted file mode 100644 index 14f7788e63..0000000000 --- a/Open-ILS/src/sql/Pg/upgrade/XXXX.schema.search_highlight_escape_html.sql +++ /dev/null @@ -1,118 +0,0 @@ -BEGIN; - --- SELECT evergreen.upgrade_deps_block_check('XXXX', :eg_version); - -CREATE OR REPLACE FUNCTION search.highlight_display_fields_impl( - rid BIGINT, - tsq TEXT, - field_list INT[] DEFAULT '{}'::INT[], - css_class TEXT DEFAULT 'oils_SH', - hl_all BOOL DEFAULT TRUE, - minwords INT DEFAULT 5, - maxwords INT DEFAULT 25, - shortwords INT DEFAULT 0, - maxfrags INT DEFAULT 0, - delimiter TEXT DEFAULT ' ... ' -) RETURNS SETOF search.highlight_result AS $f$ -DECLARE - opts TEXT := ''; - v_css_class TEXT := css_class; - v_delimiter TEXT := delimiter; - v_field_list INT[] := field_list; - hl_query TEXT; -BEGIN - IF v_delimiter LIKE $$%'%$$ OR v_delimiter LIKE '%"%' THEN --" - v_delimiter := ' ... '; - END IF; - - IF NOT hl_all THEN - opts := opts || 'MinWords=' || minwords; - opts := opts || ', MaxWords=' || maxwords; - opts := opts || ', ShortWords=' || shortwords; - opts := opts || ', MaxFragments=' || maxfrags; - opts := opts || ', FragmentDelimiter="' || delimiter || '"'; - ELSE - opts := opts || 'HighlightAll=TRUE'; - END IF; - - IF v_css_class LIKE $$%'%$$ OR v_css_class LIKE '%"%' THEN -- " - v_css_class := 'oils_SH'; - END IF; - - opts := opts || $$, StopSel=, StartSel=""$xx$ -- "' - ) AS highlight - FROM metabib.display_entry de - JOIN config.metabib_field mf ON (mf.id = de.field) - JOIN search.best_tsconfig t ON (t.id = de.field) - WHERE de.source = $2 - AND field = ANY ($3) - ORDER BY de.id;$$; - - RETURN QUERY EXECUTE hl_query USING opts, rid, v_field_list; -END; -$f$ LANGUAGE PLPGSQL; - -CREATE OR REPLACE FUNCTION search.highlight_display_fields( - rid BIGINT, - tsq_map TEXT, -- { '(a | b) & c' => '1,2,3,4', ...} - css_class TEXT DEFAULT 'oils_SH', - hl_all BOOL DEFAULT TRUE, - minwords INT DEFAULT 5, - maxwords INT DEFAULT 25, - shortwords INT DEFAULT 0, - maxfrags INT DEFAULT 0, - delimiter TEXT DEFAULT ' ... ' -) RETURNS SETOF search.highlight_result AS $f$ -DECLARE - tsq_hstore TEXT; - tsq TEXT; - fields TEXT; - afields INT[]; - seen INT[]; -BEGIN - IF (tsq_map ILIKE 'hstore%') THEN - EXECUTE 'SELECT ' || tsq_map INTO tsq_hstore; - ELSE - tsq_hstore := tsq_map::HSTORE; - END IF; - - FOR tsq, fields IN SELECT key, value FROM each(tsq_hstore::HSTORE) LOOP - SELECT ARRAY_AGG(unnest::INT) INTO afields - FROM unnest(regexp_split_to_array(fields,',')); - seen := seen || afields; - - RETURN QUERY - SELECT * FROM search.highlight_display_fields_impl( - rid, tsq, afields, css_class, hl_all,minwords, - maxwords, shortwords, maxfrags, delimiter - ); - END LOOP; - - RETURN QUERY - SELECT id, - source, - field, - evergreen.escape_for_html(value) AS value, - evergreen.escape_for_html(value) AS highlight - FROM metabib.display_entry - WHERE source = rid - AND NOT (field = ANY (seen)); -END; -$f$ LANGUAGE PLPGSQL ROWS 10; - -COMMIT;