Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
haskell-gargantext
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Christian Merten
haskell-gargantext
Commits
87b64d29
Commit
87b64d29
authored
Sep 04, 2023
by
Alfredo Di Napoli
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add test for searchInCorpus
parent
2c4e9d9a
Changes
12
Show whitespace changes
Inline
Side-by-side
Showing
12 changed files
with
101 additions
and
58 deletions
+101
-58
Main.hs
bin/gargantext-init/Main.hs
+1
-1
gargantext.cabal
gargantext.cabal
+2
-2
Flow.hs
src/Gargantext/Database/Action/Flow.hs
+1
-1
Search.hs
src/Gargantext/Database/Action/Search.hs
+18
-12
ContextNodeNgrams.hs
src/Gargantext/Database/Admin/Trigger/ContextNodeNgrams.hs
+4
-3
Contexts.hs
src/Gargantext/Database/Admin/Trigger/Contexts.hs
+4
-3
Init.hs
src/Gargantext/Database/Admin/Trigger/Init.hs
+4
-3
NodesContexts.hs
src/Gargantext/Database/Admin/Trigger/NodesContexts.hs
+6
-5
Prelude.hs
src/Gargantext/Database/Prelude.hs
+2
-2
Node.hs
src/Gargantext/Database/Query/Table/Node.hs
+3
-3
Operations.hs
test/Database/Operations.hs
+24
-6
DocumentSearch.hs
test/Database/Operations/DocumentSearch.hs
+32
-17
No files found.
bin/gargantext-init/Main.hs
View file @
87b64d29
...
@@ -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
::
DB
Cmd
GargError
[
Int64
])
_
<-
runCmdDev
env
createUsers
_
<-
runCmdDev
env
createUsers
x
<-
runCmdDev
env
initMaster
x
<-
runCmdDev
env
initMaster
_
<-
runCmdDev
env
mkRoots
_
<-
runCmdDev
env
mkRoots
...
...
gargantext.cabal
View file @
87b64d29
...
@@ -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
...
...
src/Gargantext/Database/Action/Flow.hs
View file @
87b64d29
...
@@ -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
...
...
src/Gargantext/Database/Action/Search.hs
View file @
87b64d29
...
@@ -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
)]
->
DB
Cmd
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
]
->
DB
Cmd
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
]
->
DB
Cmd
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
)
::
DB
Cmd
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
]
->
DB
Cmd
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
->
DB
Cmd
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
]
->
DB
Cmd
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
...
...
src/Gargantext/Database/Admin/Trigger/ContextNodeNgrams.hs
View file @
87b64d29
...
@@ -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
=>
DB
Cmd
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
=>
DB
Cmd
err
Int64
triggerCountInsert2
=
execPGSQuery
query
(
toDBid
NodeCorpus
triggerCountInsert2
=
execPGSQuery
query
(
toDBid
NodeCorpus
,
toDBid
NodeDocument
,
toDBid
NodeDocument
,
toDBid
NodeList
,
toDBid
NodeList
...
...
src/Gargantext/Database/Admin/Trigger/Contexts.hs
View file @
87b64d29
...
@@ -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
=>
DB
Cmd
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
->
DB
Cmd
err
Int64
triggerUpdateHash
secret
=
execPGSQuery
query
(
toDBid
NodeDocument
triggerUpdateHash
secret
=
execPGSQuery
query
(
toDBid
NodeDocument
,
toDBid
NodeContact
,
toDBid
NodeContact
,
secret
,
secret
...
...
src/Gargantext/Database/Admin/Trigger/Init.hs
View file @
87b64d29
...
@@ -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
->
DB
Cmd
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
->
DB
Cmd
err
[
Int64
]
initLastTriggers
lId
=
do
initLastTriggers
lId
=
do
t0
<-
triggerSearchUpdate
t0
<-
triggerSearchUpdate
t1
<-
triggerCountInsert
t1
<-
triggerCountInsert
...
...
src/Gargantext/Database/Admin/Trigger/NodesContexts.hs
View file @
87b64d29
...
@@ -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
->
DB
Cmd
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
->
DB
Cmd
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
->
DB
Cmd
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
->
DB
Cmd
err
Int64
triggerDeleteCount
lId
=
execPGSQuery
query
(
lId
,
toDBid
NodeList
)
triggerDeleteCount
lId
=
execPGSQuery
query
(
lId
,
toDBid
NodeList
)
where
where
query
::
DPS
.
Query
query
::
DPS
.
Query
...
...
src/Gargantext/Database/Prelude.hs
View file @
87b64d29
...
@@ -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
->
DB
Cmd
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
->
DB
Cmd
err
Int64
execPGSQuery
q
a
=
mkCmd
$
\
conn
->
PGS
.
execute
conn
q
a
execPGSQuery
q
a
=
mkCmd
$
\
conn
->
PGS
.
execute
conn
q
a
------------------------------------------------------------------------
------------------------------------------------------------------------
...
...
src/Gargantext/Database/Query/Table/Node.hs
View file @
87b64d29
...
@@ -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
]
->
DB
Cmd
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
->
DB
Cmd
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
->
DB
Cmd
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
...
...
test/Database/Operations.hs
View file @
87b64d29
...
@@ -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
4
09
liftIO
$
corpusId
`
shouldBe
`
NodeId
4
16
-- 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
)
...
...
test/Database/Operations/DocumentSearch.hs
View file @
87b64d29
...
@@ -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
uid
<-
getUserId
(
UserName
"alfredo"
)
parentId
<-
getRootId
(
UserName
"gargantua"
)
void
$
mk
(
Just
"Test_Corpus"
)
(
Nothing
::
Maybe
HyperdataCorpus
)
parentId
uid
[
corpus
]
<-
getCorporaWithParentId
parentId
[
corpus
]
<-
getCorporaWithParentId
parentId
let
corpusId
=
_node_id
corpus
_
ids
<-
addDocumentsToHyperCorpus
nlpServerConfig
ids
<-
addDocumentsToHyperCorpus
nlpServerConfig
(
Just
$
_node_hyperdata
$
corpus
)
(
Just
$
_node_hyperdata
$
corpus
)
(
Multi
EN
)
(
Multi
EN
)
(
_node_id
corpus
)
corpusId
[
exampleDocument_01
]
[
exampleDocument_01
,
exampleDocument_02
]
pure
()
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"
)
[
corpus
]
<-
getCorporaWithParentId
parentId
results1
<-
searchInCorpus
(
_node_id
corpus
)
False
[
"mineral"
]
Nothing
Nothing
Nothing
results2
<-
searchInCorpus
(
_node_id
corpus
)
False
[
"computational"
]
Nothing
Nothing
Nothing
liftIO
$
length
results1
`
shouldBe
`
1
liftIO
$
length
results2
`
shouldBe
`
1
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment