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

Merge remote-tracking branch 'origin/dev-ngrams-table' into dev

parents 0363ab15 57b1dd42
......@@ -163,6 +163,7 @@ instance ToSchema a => ToSchema (PatchSet a)
instance ToSchema a => ToSchema (Replace a) where
declareNamedSchema (_ :: proxy (Replace a)) = do
-- TODO Keep constructor is not supported here.
aSchema <- declareSchemaRef (Proxy :: Proxy a)
return $ NamedSchema (Just "Replace") $ mempty
& type_ .~ SwaggerObject
......@@ -174,7 +175,7 @@ instance ToSchema a => ToSchema (Replace a) where
& required .~ [ "old", "new" ]
data NgramsPatch =
NgramsPatch { _patch_children :: PatchSet NgramsElement
NgramsPatch { _patch_children :: PatchSet NgramsTerm
, _patch_list :: Replace ListType -- TODO Map UserId ListType
}
deriving (Ord, Eq, Show, Generic)
......@@ -275,13 +276,13 @@ mkListsUpdate lId patches =
]
mkChildrenGroups :: ListId
-> (PatchSet NgramsElement -> Set NgramsElement)
-> (PatchSet NgramsTerm -> Set NgramsTerm)
-> NgramsTablePatch
-> [(ListId, NgramsParent, NgramsChild, Maybe Double)]
mkChildrenGroups lId addOrRem patches =
[ (lId, parent, child, Just 1)
| (parent, patch) <- patches ^.. ntp_ngrams_patches . ifolded . withIndex
, child <- patch ^.. patch_children . to addOrRem . folded . ne_ngrams
, child <- patch ^.. patch_children . to addOrRem . folded
]
-- Apply the given patch to the DB and returns the patch to be applied on the
......
......@@ -126,8 +126,8 @@ updateNodeNgrams' input = map (\(PGS.Only a) -> a) <$>
from (?) as new(node_id,terms,typeList)
JOIN ngrams ON ngrams.terms = new.terms
WHERE old.node_id = new.node_id
AND old.ngram_id = ngrams.id;
-- RETURNING new.ngram_id
AND old.ngram_id = ngrams.id
RETURNING old.ngram_id;
|]
data NodeNgramsUpdate = NodeNgramsUpdate
......
......@@ -135,20 +135,24 @@ ngramsGroup action ngs = runNodeNgramsNgrams q ngs
Add -> queryInsertNodeNgramsNgrams
runNodeNgramsNgrams :: PGS.Query -> [(ListId, NgramsParent, NgramsChild, Maybe Double)] -> Cmd err [Int]
runNodeNgramsNgrams :: PGS.Query -> [(ListId, NgramsParent, NgramsChild{-, Maybe Double-})] -> Cmd err [Int]
runNodeNgramsNgrams q ngs = map (\(PGS.Only a) -> a) <$> runPGSQuery q (PGS.Only $ Values fields ngs' )
where
ngs' = map (\(n,ng1,ng2,w) -> (n,ng1,ng2,maybe 0 identity w)) ngs
ngs' = map (\(n,ng1,ng2{-,w-}) -> (n,ng1,ng2{-,maybe 0 identity w-})) ngs
fields = map (\t -> QualifiedIdentifier Nothing t)
["int4","text","text","double"]
["int4","text","text"{-,"double precision"-}]
--------------------------------------------------------------------
-- TODO: on conflict update weight
queryInsertNodeNgramsNgrams :: PGS.Query
queryInsertNodeNgramsNgrams = [sql|
WITH input_rows(nId,ng1,ng2,w) AS (?)
WITH input_rows(nId,ng1,ng2
-- ,w
) AS (?)
INSERT INTO nodes_ngrams_ngrams (node_id,ngram1_id,ngram2_id,weight)
SELECT nId,ngrams1.id,ngrams2.id,w FROM input_rows
SELECT nId,ngrams1.id,ngrams2.id
-- ,w
FROM input_rows
JOIN ngrams ngrams1 ON ngrams1.terms = ng1
JOIN ngrams ngrams2 ON ngrams2.terms = ng2
ON CONFLICT (node_id,ngram1_id,ngram2_id) DO NOTHING -- unique index created here
......
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