Commit c9cd5e03 authored by Alexandre Delanoë's avatar Alexandre Delanoë

[FIX] Scores at insertion

parent 4e3342db
...@@ -28,7 +28,7 @@ import Database.PostgreSQL.Simple.Types (Values(..), QualifiedIdentifier(..)) ...@@ -28,7 +28,7 @@ import Database.PostgreSQL.Simple.Types (Values(..), QualifiedIdentifier(..))
import Gargantext.Core import Gargantext.Core
import Gargantext.API.Ngrams.Types (NgramsTerm(..)) import Gargantext.API.Ngrams.Types (NgramsTerm(..))
import Gargantext.Data.HashMap.Strict.Utils as HM import Gargantext.Data.HashMap.Strict.Utils as HM
import Gargantext.Database.Admin.Types.Node -- (ListId, CorpusId, NodeId) import Gargantext.Database.Admin.Types.Node (ListId, CorpusId, NodeId(..), ContextId, MasterCorpusId, NodeType(NodeDocument), UserCorpusId, DocId)
import Gargantext.Database.Prelude (Cmd, runPGSQuery) import Gargantext.Database.Prelude (Cmd, runPGSQuery)
import Gargantext.Database.Schema.Ngrams (ngramsTypeId, NgramsType(..)) import Gargantext.Database.Schema.Ngrams (ngramsTypeId, NgramsType(..))
import Gargantext.Prelude import Gargantext.Prelude
......
...@@ -35,14 +35,18 @@ triggerInsertCount lId = execPGSQuery query (lId, nodeTypeId NodeList) ...@@ -35,14 +35,18 @@ triggerInsertCount lId = execPGSQuery query (lId, nodeTypeId NodeList)
AS $$ AS $$
BEGIN BEGIN
INSERT INTO node_node_ngrams (node1_id, node2_id, ngrams_id, ngrams_type, weight) INSERT INTO node_node_ngrams (node1_id, node2_id, ngrams_id, ngrams_type, weight)
SELECT new1.node_id, lists.id, nnn.ngrams_id, nnn.ngrams_type, count(*) as weight SELECT lists.parent_id
, lists.id
, cnn.ngrams_id
, cnn.ngrams_type
, count(*) AS weight
FROM NEW as new1 FROM NEW as new1
INNER JOIN contexts doc ON doc.id = new1.context_id INNER JOIN contexts doc ON doc.id = new1.context_id
INNER JOIN nodes lists ON lists.parent_id = new1.node_id INNER JOIN nodes lists ON lists.parent_id = lists.parent_id
INNER JOIN context_node_ngrams nnn ON nnn.context_id = doc.id INNER JOIN context_node_ngrams cnn ON cnn.context_id = doc.id
WHERE lists.id in (?, lists.id) WHERE lists.id in (?, lists.id)
AND lists.typename = ? AND lists.typename = ?
GROUP BY new1.node_id, lists.id, nnn.ngrams_id, nnn.ngrams_type GROUP BY lists.parent_id, lists.id, cnn.ngrams_id, cnn.ngrams_type
ON CONFLICT (node1_id, node2_id, ngrams_id, ngrams_type) ON CONFLICT (node1_id, node2_id, ngrams_id, ngrams_type)
DO UPDATE set weight = node_node_ngrams.weight + excluded.weight DO UPDATE set weight = node_node_ngrams.weight + excluded.weight
; ;
......
...@@ -212,6 +212,7 @@ pgContextId = pgNodeId ...@@ -212,6 +212,7 @@ pgContextId = pgNodeId
newtype NodeId = NodeId Int newtype NodeId = NodeId Int
deriving (Read, Generic, Num, Eq, Ord, Enum, ToJSONKey, FromJSONKey, ToJSON, FromJSON, Hashable, Csv.ToField) deriving (Read, Generic, Num, Eq, Ord, Enum, ToJSONKey, FromJSONKey, ToJSON, FromJSON, Hashable, Csv.ToField)
-- TODO make another type? -- TODO make another type?
type ContextId = NodeId type ContextId = NodeId
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment