2 Module : Gargantext.Database.Admin.Trigger.Nodes
3 Description : Triggers configuration
4 Copyright : (c) CNRS, 2017-Present
5 License : AGPL + CECILL v3
6 Maintainer : team@gargantext.org
7 Stability : experimental
10 Triggers on Nodes table.
14 {-# LANGUAGE FlexibleContexts #-}
15 {-# LANGUAGE QuasiQuotes #-}
16 {-# LANGUAGE NoImplicitPrelude #-}
17 {-# LANGUAGE OverloadedStrings #-}
18 {-# LANGUAGE RankNTypes #-}
20 module Gargantext.Database.Admin.Trigger.Nodes
23 import Database.PostgreSQL.Simple.SqlQQ (sql)
24 import Gargantext.Database.Admin.Config (nodeTypeId)
25 import Gargantext.Database.Admin.Types.Node -- (ListId, CorpusId, NodeId)
26 import Gargantext.Database.Prelude (Cmd, execPGSQuery)
27 import Gargantext.Prelude
28 import qualified Database.PostgreSQL.Simple as DPS
31 triggerSearchUpdate :: Cmd err Int64
32 triggerSearchUpdate = execPGSQuery query ( nodeTypeId NodeDocument
33 , nodeTypeId NodeDocument
34 , nodeTypeId NodeContact
39 -- DROP TRIGGER search_update_trigger on nodes;
40 CREATE OR REPLACE FUNCTION public.search_update()
43 IF new.typename = ? AND new.hyperdata @> '{"language_iso2":"EN"}' THEN
44 new.search := to_tsvector( 'english' , (new.hyperdata ->> 'title') || ' ' || (new.hyperdata ->> 'abstract'));
46 ELSIF new.typename = ? AND new.hyperdata @> '{"language_iso2":"FR"}' THEN
47 new.search := to_tsvector( 'french' , (new.hyperdata ->> 'title') || ' ' || (new.hyperdata ->> 'abstract'));
49 ELSIF new.typename = ? THEN
50 new.search := to_tsvector( 'french' , (new.hyperdata ->> 'prenom')
51 || ' ' || (new.hyperdata ->> 'nom')
52 || ' ' || (new.hyperdata ->> 'fonction')
55 new.search := to_tsvector( 'english' , (new.hyperdata ->> 'title') || ' ' || (new.hyperdata ->> 'abstract'));
61 ALTER FUNCTION public.search_update() OWNER TO gargantua;
63 CREATE TRIGGER search_update_trigger
64 BEFORE INSERT OR UPDATE
66 EXECUTE PROCEDURE search_update();
68 -- Initialize index with already existing data
69 UPDATE nodes SET hyperdata = hyperdata;