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

Merge remote-tracking branch 'origin/551-dev-graphql-contexts-ngrams' into dev-merge

parents 29592e7e aa382ab1
...@@ -48,6 +48,8 @@ services: ...@@ -48,6 +48,8 @@ services:
- postgres - postgres
links: links:
- postgres - postgres
volumes:
- pgadmin:/var/lib/pgadmin
corenlp: corenlp:
image: 'cgenie/corenlp-garg' image: 'cgenie/corenlp-garg'
...@@ -65,3 +67,4 @@ volumes: ...@@ -65,3 +67,4 @@ volumes:
#garg-pgdata: #garg-pgdata:
garg-pgdata14: garg-pgdata14:
js-cache: js-cache:
pgadmin:
...@@ -227,18 +227,27 @@ getContextNgramsMatchingFTS :: HasNodeError err ...@@ -227,18 +227,27 @@ getContextNgramsMatchingFTS :: HasNodeError err
-> NodeId -> NodeId
-> Cmd err [Text] -> Cmd err [Text]
getContextNgramsMatchingFTS contextId listId = do getContextNgramsMatchingFTS contextId listId = do
res <- runPGSQuery query (contextId, listId) res <- runPGSQuery query (listId, listId, contextId)
pure $ (\(PGS.Only term) -> term) <$> res pure $ (\(PGS.Only term) -> term) <$> res
where where
query :: PGS.Query query :: PGS.Query
query = [sql| SELECT ngrams.terms query = [sql| WITH ngrams_ids AS
(SELECT ngrams_id
FROM node_stories
WHERE node_id = ?
UNION SELECT ngrams_id
FROM node_ngrams
WHERE node_id = ?)
SELECT DISTINCT ngrams.terms
FROM ngrams FROM ngrams
JOIN node_ngrams ON node_ngrams.ngrams_id = ngrams.id JOIN ngrams_ids ON ngrams_ids.ngrams_id = ngrams.id
-- JOIN node_ngrams ON node_ngrams.ngrams_id = ngrams.id
CROSS JOIN contexts CROSS JOIN contexts
WHERE contexts.id = ? WHERE contexts.id = ?
AND node_ngrams.node_id = ? -- AND node_ngrams.node_id = ?
AND contexts.search @@ plainto_tsquery(ngrams.terms) |] AND (contexts.search @@ plainto_tsquery(ngrams.terms)
OR contexts.search @@ plainto_tsquery('french', ngrams.terms)) |]
------------------------------------------------------------------------ ------------------------------------------------------------------------
insertNodeContext :: [NodeContext] -> Cmd err Int insertNodeContext :: [NodeContext] -> Cmd err Int
insertNodeContext ns = mkCmd $ \conn -> fromIntegral <$> (runInsert_ conn insertNodeContext ns = mkCmd $ \conn -> fromIntegral <$> (runInsert_ conn
......
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