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(..))
import Gargantext.Core
import Gargantext.API.Ngrams.Types (NgramsTerm(..))
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.Schema.Ngrams (ngramsTypeId, NgramsType(..))
import Gargantext.Prelude
......
......@@ -35,14 +35,18 @@ triggerInsertCount lId = execPGSQuery query (lId, nodeTypeId NodeList)
AS $$
BEGIN
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
INNER JOIN contexts doc ON doc.id = new1.context_id
INNER JOIN nodes lists ON lists.parent_id = new1.node_id
INNER JOIN context_node_ngrams nnn ON nnn.context_id = doc.id
INNER JOIN nodes lists ON lists.parent_id = lists.parent_id
INNER JOIN context_node_ngrams cnn ON cnn.context_id = doc.id
WHERE lists.id in (?, lists.id)
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)
DO UPDATE set weight = node_node_ngrams.weight + excluded.weight
;
......
......@@ -212,6 +212,7 @@ pgContextId = pgNodeId
newtype NodeId = NodeId Int
deriving (Read, Generic, Num, Eq, Ord, Enum, ToJSONKey, FromJSONKey, ToJSON, FromJSON, Hashable, Csv.ToField)
-- TODO make another type?
type ContextId = NodeId
......@@ -244,13 +245,13 @@ instance ToParamSchema NodeId
instance Arbitrary NodeId where
arbitrary = NodeId <$> arbitrary
type ParentId = NodeId
type ParentId = NodeId
type CorpusId = NodeId
type CommunityId = NodeId
type ListId = NodeId
type DocumentId = NodeId
type DocId = NodeId
type RootId = NodeId
type ListId = NodeId
type DocumentId = NodeId
type DocId = NodeId
type RootId = NodeId
type MasterCorpusId = CorpusId
type UserCorpusId = CorpusId
......
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