Commit 87b64d29 authored by Alfredo Di Napoli's avatar Alfredo Di Napoli

Add test for searchInCorpus

parent 2c4e9d9a
Pipeline #4560 failed with stages
in 24 minutes and 42 seconds
...@@ -73,7 +73,7 @@ main = do ...@@ -73,7 +73,7 @@ main = do
pure (masterUserId, masterRootId, masterCorpusId, masterListId) pure (masterUserId, masterRootId, masterCorpusId, masterListId)
withDevEnv iniPath $ \env -> do withDevEnv iniPath $ \env -> do
_ <- runCmdDev env (initFirstTriggers secret :: Cmd GargError [Int64]) _ <- runCmdDev env (initFirstTriggers secret :: DBCmd GargError [Int64])
_ <- runCmdDev env createUsers _ <- runCmdDev env createUsers
x <- runCmdDev env initMaster x <- runCmdDev env initMaster
_ <- runCmdDev env mkRoots _ <- runCmdDev env mkRoots
......
...@@ -86,6 +86,7 @@ library ...@@ -86,6 +86,7 @@ library
Gargantext.Core.Text.Terms Gargantext.Core.Text.Terms
Gargantext.Core.Text.Terms.Eleve Gargantext.Core.Text.Terms.Eleve
Gargantext.Core.Text.Terms.Mono Gargantext.Core.Text.Terms.Mono
Gargantext.Core.Text.Terms.Mono.Stem.En
Gargantext.Core.Text.Terms.Multi Gargantext.Core.Text.Terms.Multi
Gargantext.Core.Text.Terms.Multi.Lang.En Gargantext.Core.Text.Terms.Multi.Lang.En
Gargantext.Core.Text.Terms.Multi.Lang.Fr Gargantext.Core.Text.Terms.Multi.Lang.Fr
...@@ -113,6 +114,7 @@ library ...@@ -113,6 +114,7 @@ library
Gargantext.Core.Viz.Types Gargantext.Core.Viz.Types
Gargantext.Database.Action.Flow Gargantext.Database.Action.Flow
Gargantext.Database.Action.Flow.Types Gargantext.Database.Action.Flow.Types
Gargantext.Database.Action.Search
Gargantext.Database.Action.User Gargantext.Database.Action.User
Gargantext.Database.Action.User.New Gargantext.Database.Action.User.New
Gargantext.Database.Admin.Config Gargantext.Database.Admin.Config
...@@ -253,7 +255,6 @@ library ...@@ -253,7 +255,6 @@ library
Gargantext.Core.Text.Samples.PL Gargantext.Core.Text.Samples.PL
Gargantext.Core.Text.Samples.ZH Gargantext.Core.Text.Samples.ZH
Gargantext.Core.Text.Terms.Mono.Stem Gargantext.Core.Text.Terms.Mono.Stem
Gargantext.Core.Text.Terms.Mono.Stem.En
Gargantext.Core.Text.Terms.Mono.Token Gargantext.Core.Text.Terms.Mono.Token
Gargantext.Core.Text.Terms.Mono.Token.En Gargantext.Core.Text.Terms.Mono.Token.En
Gargantext.Core.Text.Terms.Multi.Group Gargantext.Core.Text.Terms.Multi.Group
...@@ -291,7 +292,6 @@ library ...@@ -291,7 +292,6 @@ library
Gargantext.Database.Action.Metrics.NgramsByContext Gargantext.Database.Action.Metrics.NgramsByContext
Gargantext.Database.Action.Metrics.TFICF Gargantext.Database.Action.Metrics.TFICF
Gargantext.Database.Action.Node Gargantext.Database.Action.Node
Gargantext.Database.Action.Search
Gargantext.Database.Action.Share Gargantext.Database.Action.Share
Gargantext.Database.Action.TSQuery Gargantext.Database.Action.TSQuery
Gargantext.Database.Admin.Access Gargantext.Database.Admin.Access
......
...@@ -324,7 +324,7 @@ addDocumentsToHyperCorpus ncs mb_hyper la corpusId docs = do ...@@ -324,7 +324,7 @@ addDocumentsToHyperCorpus ncs mb_hyper la corpusId docs = do
pure ids pure ids
------------------------------------------------------------------------ ------------------------------------------------------------------------
createNodes :: ( FlowCmdM env err m createNodes :: ( DbCmd' env err m, HasNodeError err
, MkCorpus c , MkCorpus c
) )
=> User => User
......
...@@ -11,7 +11,13 @@ Portability : POSIX ...@@ -11,7 +11,13 @@ Portability : POSIX
{-# LANGUAGE Arrows #-} {-# LANGUAGE Arrows #-}
{-# LANGUAGE LambdaCase #-} {-# LANGUAGE LambdaCase #-}
module Gargantext.Database.Action.Search where module Gargantext.Database.Action.Search (
searchInCorpus
, searchInCorpusWithContacts
, searchCountInCorpus
, searchInCorpusWithNgrams
, searchDocInDatabase
) where
import Control.Arrow (returnA) import Control.Arrow (returnA)
import Control.Lens ((^.), view) import Control.Lens ((^.), view)
...@@ -25,7 +31,7 @@ import Gargantext.Core ...@@ -25,7 +31,7 @@ import Gargantext.Core
import Gargantext.Core.Types import Gargantext.Core.Types
import Gargantext.Core.Types.Query (IsTrash, Limit, Offset) import Gargantext.Core.Types.Query (IsTrash, Limit, Offset)
import Gargantext.Database.Admin.Types.Hyperdata (HyperdataDocument(..), HyperdataContact(..)) import Gargantext.Database.Admin.Types.Hyperdata (HyperdataDocument(..), HyperdataContact(..))
import Gargantext.Database.Prelude (Cmd, runOpaQuery, runCountOpaQuery) import Gargantext.Database.Prelude (runOpaQuery, runCountOpaQuery, DBCmd)
import Gargantext.Database.Query.Facet import Gargantext.Database.Query.Facet
import Gargantext.Database.Query.Filter import Gargantext.Database.Query.Filter
import Gargantext.Database.Query.Table.Node import Gargantext.Database.Query.Table.Node
...@@ -48,7 +54,7 @@ import qualified Opaleye as O hiding (Order) ...@@ -48,7 +54,7 @@ import qualified Opaleye as O hiding (Order)
searchDocInDatabase :: HasDBid NodeType searchDocInDatabase :: HasDBid NodeType
=> ParentId => ParentId
-> Text -> Text
-> Cmd err [(NodeId, HyperdataDocument)] -> DBCmd err [(NodeId, HyperdataDocument)]
searchDocInDatabase p t = runOpaQuery (queryDocInDatabase p t) searchDocInDatabase p t = runOpaQuery (queryDocInDatabase p t)
where where
-- | Global search query where ParentId is Master Node Corpus Id -- | Global search query where ParentId is Master Node Corpus Id
...@@ -71,7 +77,7 @@ searchInCorpusWithNgrams :: HasDBid NodeType ...@@ -71,7 +77,7 @@ searchInCorpusWithNgrams :: HasDBid NodeType
-> Maybe Offset -> Maybe Offset
-> Maybe Limit -> Maybe Limit
-> Maybe OrderBy -> Maybe OrderBy
-> Cmd err [FacetDoc] -> DBCmd err [FacetDoc]
searchInCorpusWithNgrams _cId _lId _t _ngt _q _o _l _order = undefined searchInCorpusWithNgrams _cId _lId _t _ngt _q _o _l _order = undefined
-- | Compute TF-IDF for all 'ngramIds' in given 'CorpusId'. In this -- | Compute TF-IDF for all 'ngramIds' in given 'CorpusId'. In this
...@@ -79,11 +85,11 @@ searchInCorpusWithNgrams _cId _lId _t _ngt _q _o _l _order = undefined ...@@ -79,11 +85,11 @@ searchInCorpusWithNgrams _cId _lId _t _ngt _q _o _l _order = undefined
-- ratio of "number of times our terms appear in given document" and -- ratio of "number of times our terms appear in given document" and
-- "number of all terms in document" and return a sorted list of -- "number of all terms in document" and return a sorted list of
-- document ids -- document ids
tfidfAll :: (HasDBid NodeType, HasNodeError err) => CorpusId -> [Int] -> Cmd err [Int] _tfidfAll :: (HasDBid NodeType, HasNodeError err) => CorpusId -> [Int] -> DBCmd err [Int]
tfidfAll cId ngramIds = do _tfidfAll cId ngramIds = do
let ngramIdsSet = Set.fromList ngramIds let ngramIdsSet = Set.fromList ngramIds
lId <- defaultList cId lId <- defaultList cId
docsWithNgrams <- runOpaQuery (queryListWithNgrams lId ngramIds) :: Cmd err [(Int, Int, Int)] docsWithNgrams <- runOpaQuery (_queryListWithNgrams lId ngramIds) :: DBCmd err [(Int, Int, Int)]
-- NOTE The query returned docs with ANY ngramIds. We need to further -- NOTE The query returned docs with ANY ngramIds. We need to further
-- restrict to ALL ngramIds. -- restrict to ALL ngramIds.
let docsNgramsM = let docsNgramsM =
...@@ -111,8 +117,8 @@ tfidfAll cId ngramIds = do ...@@ -111,8 +117,8 @@ tfidfAll cId ngramIds = do
-- | Query for searching the 'context_node_ngrams' table so that we -- | Query for searching the 'context_node_ngrams' table so that we
-- find docs with ANY given 'ngramIds'. -- find docs with ANY given 'ngramIds'.
queryListWithNgrams :: ListId -> [Int] -> Select (Column SqlInt4, Column SqlInt4, Column SqlInt4) _queryListWithNgrams :: ListId -> [Int] -> Select (Column SqlInt4, Column SqlInt4, Column SqlInt4)
queryListWithNgrams lId ngramIds = proc () -> do _queryListWithNgrams lId ngramIds = proc () -> do
row <- queryContextNodeNgramsTable -< () row <- queryContextNodeNgramsTable -< ()
restrict -< (_cnng_node_id row) .== (pgNodeId lId) restrict -< (_cnng_node_id row) .== (pgNodeId lId)
restrict -< in_ (sqlInt4 <$> ngramIds) (_cnng_ngrams_id row) restrict -< in_ (sqlInt4 <$> ngramIds) (_cnng_ngrams_id row)
...@@ -137,7 +143,7 @@ searchInCorpus :: HasDBid NodeType ...@@ -137,7 +143,7 @@ searchInCorpus :: HasDBid NodeType
-> Maybe Offset -> Maybe Offset
-> Maybe Limit -> Maybe Limit
-> Maybe OrderBy -> Maybe OrderBy
-> Cmd err [FacetDoc] -> DBCmd err [FacetDoc]
searchInCorpus cId t q o l order = runOpaQuery searchInCorpus cId t q o l order = runOpaQuery
$ filterWith o l order $ filterWith o l order
$ queryInCorpus cId t $ queryInCorpus cId t
...@@ -148,7 +154,7 @@ searchCountInCorpus :: HasDBid NodeType ...@@ -148,7 +154,7 @@ searchCountInCorpus :: HasDBid NodeType
=> CorpusId => CorpusId
-> IsTrash -> IsTrash
-> [Text] -> [Text]
-> Cmd err Int -> DBCmd err Int
searchCountInCorpus cId t q = runCountOpaQuery searchCountInCorpus cId t q = runCountOpaQuery
$ queryInCorpus cId t $ queryInCorpus cId t
$ intercalate " | " $ intercalate " | "
...@@ -189,7 +195,7 @@ searchInCorpusWithContacts ...@@ -189,7 +195,7 @@ searchInCorpusWithContacts
-> Maybe Offset -> Maybe Offset
-> Maybe Limit -> Maybe Limit
-> Maybe OrderBy -> Maybe OrderBy
-> Cmd err [FacetPaired Int UTCTime HyperdataContact Int] -> DBCmd err [FacetPaired Int UTCTime HyperdataContact Int]
searchInCorpusWithContacts cId aId q o l _order = searchInCorpusWithContacts cId aId q o l _order =
runOpaQuery $ limit' l runOpaQuery $ limit' l
$ offset' o $ offset' o
......
...@@ -20,11 +20,12 @@ import Database.PostgreSQL.Simple.SqlQQ (sql) ...@@ -20,11 +20,12 @@ import Database.PostgreSQL.Simple.SqlQQ (sql)
import Gargantext.Core import Gargantext.Core
-- import Gargantext.Core.Types.Main (ListType(CandidateTerm)) -- import Gargantext.Core.Types.Main (ListType(CandidateTerm))
import Gargantext.Database.Admin.Types.Node -- (ListId, CorpusId, NodeId) import Gargantext.Database.Admin.Types.Node -- (ListId, CorpusId, NodeId)
import Gargantext.Database.Prelude (Cmd, execPGSQuery) -- (ListId, CorpusId, NodeId)
import Gargantext.Database.Prelude (execPGSQuery, DBCmd)
import Gargantext.Prelude import Gargantext.Prelude
import qualified Database.PostgreSQL.Simple as DPS import qualified Database.PostgreSQL.Simple as DPS
triggerCountInsert :: HasDBid NodeType => Cmd err Int64 triggerCountInsert :: HasDBid NodeType => DBCmd err Int64
triggerCountInsert = execPGSQuery query (toDBid NodeDocument, toDBid NodeList) triggerCountInsert = execPGSQuery query (toDBid NodeDocument, toDBid NodeList)
where where
query :: DPS.Query query :: DPS.Query
...@@ -60,7 +61,7 @@ triggerCountInsert = execPGSQuery query (toDBid NodeDocument, toDBid NodeList) ...@@ -60,7 +61,7 @@ triggerCountInsert = execPGSQuery query (toDBid NodeDocument, toDBid NodeList)
EXECUTE PROCEDURE set_ngrams_global_count(); EXECUTE PROCEDURE set_ngrams_global_count();
|] |]
triggerCountInsert2 :: HasDBid NodeType => Cmd err Int64 triggerCountInsert2 :: HasDBid NodeType => DBCmd err Int64
triggerCountInsert2 = execPGSQuery query ( toDBid NodeCorpus triggerCountInsert2 = execPGSQuery query ( toDBid NodeCorpus
, toDBid NodeDocument , toDBid NodeDocument
, toDBid NodeList , toDBid NodeList
......
...@@ -20,12 +20,13 @@ import Data.Text (Text) ...@@ -20,12 +20,13 @@ import Data.Text (Text)
import Database.PostgreSQL.Simple.SqlQQ (sql) import Database.PostgreSQL.Simple.SqlQQ (sql)
import Gargantext.Core (HasDBid(..)) import Gargantext.Core (HasDBid(..))
import Gargantext.Database.Admin.Types.Node -- (ListId, CorpusId, NodeId) import Gargantext.Database.Admin.Types.Node -- (ListId, CorpusId, NodeId)
import Gargantext.Database.Prelude (Cmd, execPGSQuery) -- (ListId, CorpusId, NodeId)
import Gargantext.Database.Prelude (execPGSQuery, DBCmd)
import Gargantext.Prelude import Gargantext.Prelude
import qualified Database.PostgreSQL.Simple as DPS import qualified Database.PostgreSQL.Simple as DPS
triggerSearchUpdate :: HasDBid NodeType => Cmd err Int64 triggerSearchUpdate :: HasDBid NodeType => DBCmd err Int64
triggerSearchUpdate = execPGSQuery query ( toDBid NodeDocument triggerSearchUpdate = execPGSQuery query ( toDBid NodeDocument
, toDBid NodeDocument , toDBid NodeDocument
, toDBid NodeContact , toDBid NodeContact
...@@ -69,7 +70,7 @@ triggerSearchUpdate = execPGSQuery query ( toDBid NodeDocument ...@@ -69,7 +70,7 @@ triggerSearchUpdate = execPGSQuery query ( toDBid NodeDocument
type Secret = Text type Secret = Text
triggerUpdateHash :: HasDBid NodeType => Secret -> Cmd err Int64 triggerUpdateHash :: HasDBid NodeType => Secret -> DBCmd err Int64
triggerUpdateHash secret = execPGSQuery query ( toDBid NodeDocument triggerUpdateHash secret = execPGSQuery query ( toDBid NodeDocument
, toDBid NodeContact , toDBid NodeContact
, secret , secret
......
...@@ -20,16 +20,17 @@ import Data.Text (Text) ...@@ -20,16 +20,17 @@ import Data.Text (Text)
import Gargantext.Database.Admin.Trigger.ContextNodeNgrams (triggerCountInsert, triggerCountInsert2) import Gargantext.Database.Admin.Trigger.ContextNodeNgrams (triggerCountInsert, triggerCountInsert2)
import Gargantext.Database.Admin.Trigger.Contexts (triggerSearchUpdate, triggerUpdateHash) import Gargantext.Database.Admin.Trigger.Contexts (triggerSearchUpdate, triggerUpdateHash)
import Gargantext.Database.Admin.Trigger.NodesContexts ({-triggerDeleteCount,-} triggerInsertCount, triggerUpdateAdd, triggerUpdateDel, MasterListId) -- , triggerCoocInsert) import Gargantext.Database.Admin.Trigger.NodesContexts ({-triggerDeleteCount,-} triggerInsertCount, triggerUpdateAdd, triggerUpdateDel, MasterListId) -- , triggerCoocInsert)
import Gargantext.Database.Prelude (Cmd) -- , triggerCoocInsert)
import Gargantext.Database.Prelude (DBCmd)
import Gargantext.Prelude import Gargantext.Prelude
------------------------------------------------------------------------ ------------------------------------------------------------------------
initFirstTriggers :: Text -> Cmd err [Int64] initFirstTriggers :: Text -> DBCmd err [Int64]
initFirstTriggers secret = do initFirstTriggers secret = do
t0 <- triggerUpdateHash secret t0 <- triggerUpdateHash secret
pure [t0] pure [t0]
initLastTriggers :: MasterListId -> Cmd err [Int64] initLastTriggers :: MasterListId -> DBCmd err [Int64]
initLastTriggers lId = do initLastTriggers lId = do
t0 <- triggerSearchUpdate t0 <- triggerSearchUpdate
t1 <- triggerCountInsert t1 <- triggerCountInsert
......
...@@ -20,13 +20,14 @@ import Database.PostgreSQL.Simple.SqlQQ (sql) ...@@ -20,13 +20,14 @@ import Database.PostgreSQL.Simple.SqlQQ (sql)
import Gargantext.Core import Gargantext.Core
import Gargantext.Database.Admin.Config import Gargantext.Database.Admin.Config
import Gargantext.Database.Admin.Types.Node -- (ListId, CorpusId, NodeId) import Gargantext.Database.Admin.Types.Node -- (ListId, CorpusId, NodeId)
import Gargantext.Database.Prelude (Cmd, execPGSQuery) -- (ListId, CorpusId, NodeId)
import Gargantext.Database.Prelude (execPGSQuery, DBCmd)
import Gargantext.Prelude import Gargantext.Prelude
import qualified Database.PostgreSQL.Simple as DPS import qualified Database.PostgreSQL.Simple as DPS
type MasterListId = ListId type MasterListId = ListId
triggerInsertCount :: MasterListId -> Cmd err Int64 triggerInsertCount :: MasterListId -> DBCmd err Int64
triggerInsertCount lId = execPGSQuery query (lId, nodeTypeId NodeList) triggerInsertCount lId = execPGSQuery query (lId, nodeTypeId NodeList)
where where
query :: DPS.Query query :: DPS.Query
...@@ -62,7 +63,7 @@ triggerInsertCount lId = execPGSQuery query (lId, nodeTypeId NodeList) ...@@ -62,7 +63,7 @@ triggerInsertCount lId = execPGSQuery query (lId, nodeTypeId NodeList)
|] |]
triggerUpdateAdd :: MasterListId -> Cmd err Int64 triggerUpdateAdd :: MasterListId -> DBCmd err Int64
triggerUpdateAdd lId = execPGSQuery query (lId, nodeTypeId NodeList) triggerUpdateAdd lId = execPGSQuery query (lId, nodeTypeId NodeList)
where where
query :: DPS.Query query :: DPS.Query
...@@ -102,7 +103,7 @@ triggerUpdateAdd lId = execPGSQuery query (lId, nodeTypeId NodeList) ...@@ -102,7 +103,7 @@ triggerUpdateAdd lId = execPGSQuery query (lId, nodeTypeId NodeList)
|] |]
triggerUpdateDel :: MasterListId -> Cmd err Int64 triggerUpdateDel :: MasterListId -> DBCmd err Int64
triggerUpdateDel lId = execPGSQuery query (lId, nodeTypeId NodeList) triggerUpdateDel lId = execPGSQuery query (lId, nodeTypeId NodeList)
where where
query :: DPS.Query query :: DPS.Query
...@@ -144,7 +145,7 @@ triggerUpdateDel lId = execPGSQuery query (lId, nodeTypeId NodeList) ...@@ -144,7 +145,7 @@ triggerUpdateDel lId = execPGSQuery query (lId, nodeTypeId NodeList)
triggerDeleteCount :: MasterListId -> Cmd err Int64 triggerDeleteCount :: MasterListId -> DBCmd err Int64
triggerDeleteCount lId = execPGSQuery query (lId, toDBid NodeList) triggerDeleteCount lId = execPGSQuery query (lId, toDBid NodeList)
where where
query :: DPS.Query query :: DPS.Query
......
...@@ -138,7 +138,7 @@ runOpaQuery :: Default FromFields fields haskells ...@@ -138,7 +138,7 @@ runOpaQuery :: Default FromFields fields haskells
-> DBCmd err [haskells] -> DBCmd err [haskells]
runOpaQuery q = mkCmd $ \c -> runSelect c q runOpaQuery q = mkCmd $ \c -> runSelect c q
runCountOpaQuery :: Select a -> Cmd err Int runCountOpaQuery :: Select a -> DBCmd err Int
runCountOpaQuery q = do runCountOpaQuery q = do
counts <- mkCmd $ \c -> runSelect c $ countRows q counts <- mkCmd $ \c -> runSelect c $ countRows q
-- countRows is guaranteed to return a list with exactly one row so DL.head is safe here -- countRows is guaranteed to return a list with exactly one row so DL.head is safe here
...@@ -189,7 +189,7 @@ runPGSQuery_ q = mkCmd $ \conn -> catch (PGS.query_ conn q) printError ...@@ -189,7 +189,7 @@ runPGSQuery_ q = mkCmd $ \conn -> catch (PGS.query_ conn q) printError
hPutStrLn stderr (fromQuery q) hPutStrLn stderr (fromQuery q)
throw (SomeException e) throw (SomeException e)
execPGSQuery :: PGS.ToRow a => PGS.Query -> a -> Cmd err Int64 execPGSQuery :: PGS.ToRow a => PGS.Query -> a -> DBCmd err Int64
execPGSQuery q a = mkCmd $ \conn -> PGS.execute conn q a execPGSQuery q a = mkCmd $ \conn -> PGS.execute conn q a
------------------------------------------------------------------------ ------------------------------------------------------------------------
......
...@@ -171,7 +171,7 @@ getClosestParentIdByType' nId nType = do ...@@ -171,7 +171,7 @@ getClosestParentIdByType' nId nType = do
getChildrenByType :: HasDBid NodeType getChildrenByType :: HasDBid NodeType
=> NodeId => NodeId
-> NodeType -> NodeType
-> Cmd err [NodeId] -> DBCmd err [NodeId]
getChildrenByType nId nType = do getChildrenByType nId nType = do
result <- runPGSQuery query (PGS.Only nId) result <- runPGSQuery query (PGS.Only nId)
children_lst <- mapM (\(id, _) -> getChildrenByType id nType) result children_lst <- mapM (\(id, _) -> getChildrenByType id nType) result
...@@ -275,7 +275,7 @@ insertDefaultNode :: HasDBid NodeType ...@@ -275,7 +275,7 @@ insertDefaultNode :: HasDBid NodeType
insertDefaultNode nt p u = insertNode nt Nothing Nothing p u insertDefaultNode nt p u = insertNode nt Nothing Nothing p u
insertDefaultNodeIfNotExists :: HasDBid NodeType insertDefaultNodeIfNotExists :: HasDBid NodeType
=> NodeType -> ParentId -> UserId -> Cmd err [NodeId] => NodeType -> ParentId -> UserId -> DBCmd err [NodeId]
insertDefaultNodeIfNotExists nt p u = do insertDefaultNodeIfNotExists nt p u = do
children <- getChildrenByType p nt children <- getChildrenByType p nt
case children of case children of
...@@ -406,7 +406,7 @@ getOrMkList pId uId = ...@@ -406,7 +406,7 @@ getOrMkList pId uId =
mkList' pId' uId' = maybe (nodeError MkNode) pure . headMay =<< insertDefaultNode NodeList pId' uId' mkList' pId' uId' = maybe (nodeError MkNode) pure . headMay =<< insertDefaultNode NodeList pId' uId'
-- | TODO remove defaultList -- | TODO remove defaultList
defaultList :: (HasNodeError err, HasDBid NodeType) => CorpusId -> Cmd err ListId defaultList :: (HasNodeError err, HasDBid NodeType) => CorpusId -> DBCmd err ListId
defaultList cId = defaultList cId =
maybe (nodeError (NoListFound cId)) (pure . view node_id) . headMay =<< getListsWithParentId cId maybe (nodeError (NoListFound cId)) (pure . view node_id) . headMay =<< getListsWithParentId cId
......
...@@ -22,7 +22,7 @@ import Gargantext.Database.Action.User ...@@ -22,7 +22,7 @@ import Gargantext.Database.Action.User
import Gargantext.Database.Action.User.New import Gargantext.Database.Action.User.New
import Gargantext.Database.Admin.Types.Hyperdata.Corpus import Gargantext.Database.Admin.Types.Hyperdata.Corpus
import Gargantext.Database.Admin.Types.Node import Gargantext.Database.Admin.Types.Node
import Gargantext.Database.Query.Table.Node (mk, getCorporaWithParentId) import Gargantext.Database.Query.Table.Node (mk, getCorporaWithParentId, getOrMkList)
import Gargantext.Database.Query.Tree.Root (getRootId) import Gargantext.Database.Query.Tree.Root (getRootId)
import Gargantext.Database.Schema.Node (NodePoly(..)) import Gargantext.Database.Schema.Node (NodePoly(..))
import Gargantext.Prelude import Gargantext.Prelude
...@@ -44,6 +44,9 @@ import Test.Hspec ...@@ -44,6 +44,9 @@ import Test.Hspec
import Test.QuickCheck.Monadic import Test.QuickCheck.Monadic
import Test.Tasty.HUnit hiding (assert) import Test.Tasty.HUnit hiding (assert)
import Test.Tasty.QuickCheck import Test.Tasty.QuickCheck
import Gargantext.Database.Admin.Trigger.Init
import Gargantext.Database.Action.Flow
import Gargantext.Database.Admin.Config (userMaster, corpusMasterName)
-- | Keeps a log of usernames we have already generated, so that our -- | Keeps a log of usernames we have already generated, so that our
-- roundtrip tests won't fail. -- roundtrip tests won't fail.
...@@ -110,6 +113,8 @@ withTestDB = bracket setup teardown ...@@ -110,6 +113,8 @@ withTestDB = bracket setup teardown
tests :: Spec tests :: Spec
tests = sequential $ aroundAll withTestDB $ describe "Database" $ do tests = sequential $ aroundAll withTestDB $ describe "Database" $ do
describe "Prelude" $ do
it "setup DB triggers" setupEnvironment
describe "Read/Writes" $ do describe "Read/Writes" $ do
describe "User creation" $ do describe "User creation" $ do
it "Simple write/read" writeRead01 it "Simple write/read" writeRead01
...@@ -119,6 +124,9 @@ tests = sequential $ aroundAll withTestDB $ describe "Database" $ do ...@@ -119,6 +124,9 @@ tests = sequential $ aroundAll withTestDB $ describe "Database" $ do
it "Simple write/read" corpusReadWrite01 it "Simple write/read" corpusReadWrite01
it "Can add language to Corpus" corpusAddLanguage it "Can add language to Corpus" corpusAddLanguage
it "Can add documents to a Corpus" corpusAddDocuments it "Can add documents to a Corpus" corpusAddDocuments
describe "Corpus search" $ do
it "Can stem query terms" stemmingTest
it "Can perform a simple search inside documents" corpusSearch01
data ExpectedActual a = data ExpectedActual a =
Expected a Expected a
...@@ -130,6 +138,16 @@ instance Eq a => Eq (ExpectedActual a) where ...@@ -130,6 +138,16 @@ instance Eq a => Eq (ExpectedActual a) where
(Actual a) == (Expected b) = a == b (Actual a) == (Expected b) = a == b
_ == _ = False _ == _ = False
setupEnvironment :: TestEnv -> IO ()
setupEnvironment env = flip runReaderT env $ runTestMonad $ do
void $ initFirstTriggers "secret_key"
void $ new_user $ mkNewUser (userMaster <> "@cnrs.com") (GargPassword "secret_key")
(masterUserId, _masterRootId, masterCorpusId)
<- getOrMk_RootWithCorpus (UserName userMaster)
(Left corpusMasterName)
(Nothing :: Maybe HyperdataCorpus)
masterListId <- getOrMkList masterCorpusId masterUserId
void $ initLastTriggers masterListId
writeRead01 :: TestEnv -> Assertion writeRead01 :: TestEnv -> Assertion
writeRead01 env = do writeRead01 env = do
...@@ -140,14 +158,14 @@ writeRead01 env = do ...@@ -140,14 +158,14 @@ writeRead01 env = do
uid1 <- new_user nur1 uid1 <- new_user nur1
uid2 <- new_user nur2 uid2 <- new_user nur2
liftBase $ uid1 `shouldBe` 1 liftBase $ uid1 `shouldBe` 2
liftBase $ uid2 `shouldBe` 2 liftBase $ uid2 `shouldBe` 3
-- Getting the users by username returns the expected IDs -- Getting the users by username returns the expected IDs
uid1' <- getUserId (UserName "alfredo") uid1' <- getUserId (UserName "alfredo")
uid2' <- getUserId (UserName "paul") uid2' <- getUserId (UserName "paul")
liftBase $ uid1' `shouldBe` 1 liftBase $ uid1' `shouldBe` 2
liftBase $ uid2' `shouldBe` 2 liftBase $ uid2' `shouldBe` 3
mkUserDup :: TestEnv -> Assertion mkUserDup :: TestEnv -> Assertion
mkUserDup env = do mkUserDup env = do
...@@ -184,7 +202,7 @@ corpusReadWrite01 env = do ...@@ -184,7 +202,7 @@ corpusReadWrite01 env = do
uid <- getUserId (UserName "alfredo") uid <- getUserId (UserName "alfredo")
parentId <- getRootId (UserName "alfredo") parentId <- getRootId (UserName "alfredo")
[corpusId] <- mk (Just "Test_Corpus") (Nothing :: Maybe HyperdataCorpus) parentId uid [corpusId] <- mk (Just "Test_Corpus") (Nothing :: Maybe HyperdataCorpus) parentId uid
liftIO $ corpusId `shouldBe` NodeId 409 liftIO $ corpusId `shouldBe` NodeId 416
-- Retrieve the corpus by Id -- Retrieve the corpus by Id
[corpus] <- getCorporaWithParentId parentId [corpus] <- getCorporaWithParentId parentId
liftIO $ corpusId `shouldBe` (_node_id corpus) liftIO $ corpusId `shouldBe` (_node_id corpus)
......
...@@ -11,24 +11,25 @@ import Data.Maybe ...@@ -11,24 +11,25 @@ import Data.Maybe
import Gargantext.Core import Gargantext.Core
import Gargantext.Core.Types.Individu import Gargantext.Core.Types.Individu
import Gargantext.Database.Action.Flow import Gargantext.Database.Action.Flow
import Gargantext.Database.Action.User import Gargantext.Database.Action.Search
import Gargantext.Database.Action.User.New
import Gargantext.Database.Admin.Types.Hyperdata.Corpus
import Gargantext.Database.Admin.Types.Hyperdata.Document import Gargantext.Database.Admin.Types.Hyperdata.Document
import Gargantext.Database.Query.Table.Node import Gargantext.Database.Query.Table.Node
import Gargantext.Database.Query.Tree.Root import Gargantext.Database.Query.Tree.Root
import Gargantext.Database.Schema.Node (NodePoly(..)) import Gargantext.Database.Schema.Node (NodePoly(..))
import Network.URI (parseURI) import Network.URI (parseURI)
import Test.Tasty.HUnit
import Database.Operations.Types import Database.Operations.Types
import Test.Hspec.Expectations
import Test.Tasty.HUnit
import Gargantext.Core.Text.Terms.Mono.Stem.En
import Gargantext.Database.Admin.Config (userMaster)
exampleDocument_01 :: HyperdataDocument exampleDocument_01 :: HyperdataDocument
exampleDocument_01 = either error id $ parseEither parseJSON $ [aesonQQ| exampleDocument_01 = either error id $ parseEither parseJSON $ [aesonQQ|
{ "doi":"sdfds" { "doi":"sdfds"
, "publication_day":6 , "publication_day":6
, "language_iso2":"en" , "language_iso2":"EN"
, "publication_minute":0 , "publication_minute":0
, "publication_month":7 , "publication_month":7
, "language_iso3":"eng" , "language_iso3":"eng"
...@@ -49,7 +50,7 @@ exampleDocument_02 :: HyperdataDocument ...@@ -49,7 +50,7 @@ exampleDocument_02 :: HyperdataDocument
exampleDocument_02 = either error id $ parseEither parseJSON $ [aesonQQ| exampleDocument_02 = either error id $ parseEither parseJSON $ [aesonQQ|
{ "doi":"sdfds" { "doi":"sdfds"
, "publication_day":6 , "publication_day":6
, "language_iso2":"en" , "language_iso2":"EN"
, "publication_minute":0 , "publication_minute":0
, "publication_month":7 , "publication_month":7
, "language_iso3":"eng" , "language_iso3":"eng"
...@@ -74,19 +75,33 @@ nlpServerConfig = ...@@ -74,19 +75,33 @@ nlpServerConfig =
corpusAddDocuments :: TestEnv -> Assertion corpusAddDocuments :: TestEnv -> Assertion
corpusAddDocuments env = do corpusAddDocuments env = do
flip runReaderT env $ runTestMonad $ do flip runReaderT env $ runTestMonad $ do
-- NOTE(adn) We need to create user 'gargantua'(!!) in order -- NOTE(adn) We need to create user 'gargantua'(!!) in order
-- for 'addDocumentsToHyperCorpus' to work. -- for 'addDocumentsToHyperCorpus' to work.
let nur = mkNewUser "gargantua@foo.com" (GargPassword "my_secret") parentId <- getRootId (UserName userMaster)
void $ new_user nur [corpus] <- getCorporaWithParentId parentId
uid <- getUserId (UserName "alfredo") let corpusId = _node_id corpus
ids <- addDocumentsToHyperCorpus nlpServerConfig
(Just $ _node_hyperdata $ corpus)
(Multi EN)
corpusId
[exampleDocument_01, exampleDocument_02]
liftIO $ length ids `shouldBe` 2
stemmingTest :: TestEnv -> Assertion
stemmingTest _env = do
stemIt "Ajeje" `shouldBe` "Ajeje"
stemIt "PyPlasm:" `shouldBe` "PyPlasm:"
corpusSearch01 :: TestEnv -> Assertion
corpusSearch01 env = do
flip runReaderT env $ runTestMonad $ do
parentId <- getRootId (UserName "gargantua") parentId <- getRootId (UserName "gargantua")
void $ mk (Just "Test_Corpus") (Nothing :: Maybe HyperdataCorpus) parentId uid
[corpus] <- getCorporaWithParentId parentId [corpus] <- getCorporaWithParentId parentId
_ids <- addDocumentsToHyperCorpus nlpServerConfig results1 <- searchInCorpus (_node_id corpus) False ["mineral"] Nothing Nothing Nothing
(Just $ _node_hyperdata $ corpus) results2 <- searchInCorpus (_node_id corpus) False ["computational"] Nothing Nothing Nothing
(Multi EN)
(_node_id corpus) liftIO $ length results1 `shouldBe` 1
[exampleDocument_01] liftIO $ length results2 `shouldBe` 1
pure ()
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