From cd688dbc73f1470daf4abb609d38f8ca7da5c3fc Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Thu, 21 Apr 2016 00:28:32 +0100 Subject: Add textclean function --- gentoobrowse-api/db/schema.sql | 9 +++++++++ gentoobrowse-api/service/sql/maintenance/categoryInsert.sql | 2 +- gentoobrowse-api/service/sql/maintenance/categoryUpdate.sql | 2 +- 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/gentoobrowse-api/db/schema.sql b/gentoobrowse-api/db/schema.sql index 4222c8e..105ce3f 100644 --- a/gentoobrowse-api/db/schema.sql +++ b/gentoobrowse-api/db/schema.sql @@ -46,6 +46,15 @@ BEGIN END $$; ALTER FUNCTION gentoobrowse.bugfts(b bugs) OWNER TO gentoo; +-- Name: textclean(text); Type: FUNCTION; Schema: gentoobrowse; Owner: gentoo +CREATE FUNCTION textclean(t text) RETURNS text + LANGUAGE plpgsql IMMUTABLE + AS $$ +BEGIN + RETURN TRIM(REGEXP_REPLACE(t, '\s+', ' ', 'g')); +END +$$; +ALTER FUNCTION gentoobrowse.textclean(t text) OWNER TO gentoo; -- Name: ebuildfilter(text); Type: FUNCTION; Schema: gentoobrowse; Owner: gentoo CREATE FUNCTION ebuildfilter(atomspec text) RETURNS SETOF integer LANGUAGE plpgsql diff --git a/gentoobrowse-api/service/sql/maintenance/categoryInsert.sql b/gentoobrowse-api/service/sql/maintenance/categoryInsert.sql index 8c3f685..fa8a1ca 100644 --- a/gentoobrowse-api/service/sql/maintenance/categoryInsert.sql +++ b/gentoobrowse-api/service/sql/maintenance/categoryInsert.sql @@ -1,2 +1,2 @@ INSERT INTO gentoobrowse.categories(summary, name) -VALUES(?, ?) +VALUES(gentoobrowse.textclean(?), ?) diff --git a/gentoobrowse-api/service/sql/maintenance/categoryUpdate.sql b/gentoobrowse-api/service/sql/maintenance/categoryUpdate.sql index 1b0ef38..28c45b1 100644 --- a/gentoobrowse-api/service/sql/maintenance/categoryUpdate.sql +++ b/gentoobrowse-api/service/sql/maintenance/categoryUpdate.sql @@ -1,3 +1,3 @@ UPDATE gentoobrowse.categories SET - summary = ? + summary = gentoobrowse.textclean(?) WHERE name = ? -- cgit v1.2.3