]> Git — Sourcephile - gargantext.git/blob - src/Gargantext/Database/NodeNgramNgram.hs
[FacetDoc] Adding Favorite Left Join and Ngrams count queries.
[gargantext.git] / src / Gargantext / Database / NodeNgramNgram.hs
1 {-# LANGUAGE TemplateHaskell #-}
2 {-# LANGUAGE FlexibleInstances #-}
3 {-# LANGUAGE MultiParamTypeClasses #-}
4 {-# LANGUAGE FunctionalDependencies #-}
5 {-# LANGUAGE Arrows #-}
6 {-# OPTIONS_GHC -fno-warn-orphans #-}
7
8 module Gargantext.Database.NodeNgramNgram where
9
10 import Prelude
11 import Data.Maybe (Maybe)
12 import Data.Profunctor.Product.TH (makeAdaptorAndInstance)
13 import Control.Lens.TH (makeLensesWith, abbreviatedFields)
14 import qualified Database.PostgreSQL.Simple as PGS
15
16 import Opaleye
17
18 data NodeNgramNgramPoly node_id ngram1_id ngram2_id weight
19 = NodeNgramNgram { nodeNgramNgram_NodeNgramNgram_NodeId :: node_id
20 , nodeNgramNgram_NodeNgramNgram_Ngram1Id :: ngram1_id
21 , nodeNgramNgram_NodeNgramNgram_Ngram2Id :: ngram2_id
22 , nodeNgramNgram_NodeNgramNgram_Weight :: weight
23 } deriving (Show)
24
25
26 type NodeNgramNgramWrite = NodeNgramNgramPoly (Maybe (Column PGInt4)) (Column PGInt4) (Column PGInt4) (Maybe (Column PGFloat8))
27 type NodeNgramNgramRead = NodeNgramNgramPoly (Column PGInt4) (Column PGInt4) (Column PGInt4) (Column PGFloat8)
28
29
30 type NodeNgramNgram = NodeNgramNgramPoly (Maybe Int) Int Int (Maybe Double)
31
32 $(makeAdaptorAndInstance "pNodeNgramNgram" ''NodeNgramNgramPoly)
33 $(makeLensesWith abbreviatedFields ''NodeNgramNgramPoly)
34
35
36 nodeNgramNgramTable :: Table NodeNgramNgramWrite NodeNgramNgramRead
37 nodeNgramNgramTable = Table "nodes_ngrams_ngrams" ( pNodeNgramNgram NodeNgramNgram
38 { nodeNgramNgram_NodeNgramNgram_NodeId = optional "node_id"
39 , nodeNgramNgram_NodeNgramNgram_Ngram1Id = required "ngram1_id"
40 , nodeNgramNgram_NodeNgramNgram_Ngram2Id = required "ngram2_id"
41 , nodeNgramNgram_NodeNgramNgram_Weight = optional "weight"
42 }
43 )
44
45
46 queryNodeNgramNgramTable :: Query NodeNgramNgramRead
47 queryNodeNgramNgramTable = queryTable nodeNgramNgramTable
48
49
50 -- | not optimized (get all ngrams without filters)
51 nodeNgramNgrams :: PGS.Connection -> IO [NodeNgramNgram]
52 nodeNgramNgrams conn = runQuery conn queryNodeNgramNgramTable
53
54 instance QueryRunnerColumnDefault PGInt4 (Maybe Int) where
55 queryRunnerColumnDefault = fieldQueryRunnerColumn
56
57 instance QueryRunnerColumnDefault PGFloat8 (Maybe Double) where
58 queryRunnerColumnDefault = fieldQueryRunnerColumn