/*
* If the unaccent extension is installed, modify the cspace_english text search configuration to
* be accent-insensitive.
+ *
+ * Also replace the nx_to_tsvector function generated by nuxeo. This is identical to nuxeo's
+ * implementation, except that it searches all namespaces for the cspace_english text search
+ * configuration, instead of using "public.cspace_english", as configured in
+ * proto-repo-config.xml. This is to work around Amazon RDS renaming the public namespace to
+ * something random during database restores.
*/
DO $$
ALTER TEXT SEARCH CONFIGURATION cspace_english
ALTER MAPPING FOR asciihword, asciiword, hword_asciipart, hword, hword_part, word
WITH unaccent, english_stem;
+
+ CREATE OR REPLACE FUNCTION nx_to_tsvector(string VARCHAR) RETURNS TSVECTOR AS $func$
+ DECLARE
+ search_namespace TEXT;
+ result TSVECTOR;
+ BEGIN
+ SELECT
+ nspname INTO search_namespace
+ FROM
+ pg_namespace
+ INNER JOIN pg_ts_config ON pg_namespace.oid = pg_ts_config.cfgnamespace
+ AND cfgname = 'cspace_english' :: text;
+
+ PERFORM set_config('search_path', search_namespace, true);
+
+ result := TO_TSVECTOR('cspace_english', SUBSTR($1, 1, 250000));
+ RETURN result;
+ END;
+ $func$ LANGUAGE plpgsql IMMUTABLE;
END IF;
END IF;