]> Git — Sourcephile - gargantext.git/blob - src/Gargantext/Database/Query/Table/Node_NodeNgramsNodeNgrams.hs
[ngrams] REFRESH MATERIALIZED VIEW CONCURRENTLY
[gargantext.git] / src / Gargantext / Database / Query / Table / Node_NodeNgramsNodeNgrams.hs
1 {-|
2 Module : Gargantext.Database.Schema.Node_NodeNgrams_NodeNgrams
3 Description :
4 Copyright : (c) CNRS, 2017-Present
5 License : AGPL + CECILL v3
6 Maintainer : team@gargantext.org
7 Stability : experimental
8 Portability : POSIX
9
10 lgrams: listed ngrams
11
12 Node_NodeNgrams_NodeNgrams table is used to group ngrams
13 - first NodeId :: Referential / space node (corpus)
14 - NodeNgrams where Node is List
15 - lgrams1_id, lgrams2_id where all lgrams2_id will be added to lgrams1_id
16 - weight: score the relation
17
18 Next Step benchmark:
19 - recursive queries of postgres
20 - group with: https://en.wikipedia.org/wiki/Nested_set_model
21
22 -}
23
24 {-# OPTIONS_GHC -fno-warn-orphans #-}
25
26 {-# LANGUAGE Arrows #-}
27 {-# LANGUAGE FunctionalDependencies #-}
28 {-# LANGUAGE QuasiQuotes #-}
29 {-# LANGUAGE TemplateHaskell #-}
30
31 module Gargantext.Database.Query.Table.Node_NodeNgramsNodeNgrams
32 where
33
34 {-
35 import Gargantext.Database.Schema.Prelude
36 import Gargantext.Database.Prelude (Cmd, runOpaQuery, mkCmd)
37 import Gargantext.Database.Admin.Types.Node (pgNodeId)
38 import Gargantext.Database.Schema.Node_NodeNgramsNodeNgrams
39 import Gargantext.Database.Schema.Node()
40 import Gargantext.Prelude
41
42
43 queryNode_NodeNgrams_NodeNgrams_Table :: Query Node_NodeNgrams_NodeNgrams_Read
44 queryNode_NodeNgrams_NodeNgrams_Table = selectTable node_NodeNgrams_NodeNgrams_Table
45
46 -- | Select NodeNgramsNgrams
47 -- TODO not optimized (get all ngrams without filters)
48 _node_Node_NodeNgrams_NodeNgrams :: Cmd err [Node_NodeNgrams_NodeNgrams]
49 _node_Node_NodeNgrams_NodeNgrams = runOpaQuery queryNode_NodeNgrams_NodeNgrams_Table
50
51
52 -- TODO: Add option on conflict
53 insert_Node_NodeNgrams_NodeNgrams :: [Node_NodeNgrams_NodeNgrams] -> Cmd err Int64
54 insert_Node_NodeNgrams_NodeNgrams = insert_Node_NodeNgrams_NodeNgrams_W
55 . map (\(Node_NodeNgrams_NodeNgrams n ng1 ng2 maybeWeight) ->
56 Node_NodeNgrams_NodeNgrams (pgNodeId n )
57 (sqlInt4 <$> ng1)
58 (sqlInt4 ng2)
59 (sqlDouble <$> maybeWeight)
60 )
61
62 insert_Node_NodeNgrams_NodeNgrams_W :: [Node_NodeNgrams_NodeNgrams_Write] -> Cmd err Int64
63 insert_Node_NodeNgrams_NodeNgrams_W ns =
64 mkCmd $ \c -> runInsert_ c Insert { iTable = node_NodeNgrams_NodeNgrams_Table
65 , iRows = ns
66 , iReturning = rCount
67 , iOnConflict = (Just DoNothing)
68 }
69 -}