 BEGIN
 	NEW.term := term_lib.normalizeterm(NEW.term); -- or kx_normalizedterm
 	NEW.kx_metaphone := term_lib.multimetaphone(NEW.term,6);  -- IMPORTANT 6, to use in ALL DEFAULTS
-	NEW.kx_tsvector  := to_tsvector( term1.lang2regconf(term1.nsget_lang(NEW.fk_ns)), NEW.term);
+	NEW.kx_tsvector  := to_tsvector( term_lib.lang2regconf(term_lib.nsget_lang(NEW.fk_ns)), NEW.term);
+	--   IF NEW.is_suspect AND NEW.jinfo->>'suspect_cause' IS NULL THEN RAISE
 	RETURN NEW;
 END;
 $f$ LANGUAGE PLpgSQL;

END;
$f$ LANGUAGE PLpgSQL;



$f$ LANGUAGE SQL IMMUTABLE;


CREATE FUNCTION term1.nsget_lang_aux(int,boolean DEFAULT false) RETURNS char(2) AS $f$
	-- 
	-- Namespace language by its nscount (or nsid when $2 false), used by proxy term_lib.nsget_lang().
	--
	SELECT lang FROM term1.ns WHERE CASE WHEN $2 THEN nscount=$1::smallint ELSE nsid=$1 END;
 	-- NULL is error, '' is a valid "no language"
$f$ LANGUAGE SQL IMMUTABLE;

CREATE FUNCTION term1.nsget_nsid(text) RETURNS int AS $f$ SELECT nsid FROM term1.ns WHERE label=$1; $f$ LANGUAGE SQL IMMUTABLE;
CREATE FUNCTION term1.nsget_nsid(int) RETURNS int AS $f$ SELECT nsid FROM term1.ns WHERE nscount=$1::smallint; $f$ LANGUAGE SQL IMMUTABLE;

