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
158
Issues
158
List
Board
Labels
Milestones
Merge Requests
11
Merge Requests
11
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
gargantext
haskell-gargantext
Commits
5efcb182
Commit
5efcb182
authored
Oct 18, 2018
by
Alexandre Delanoë
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[TAB] Opaleye query for Document view (todo: date + title later).
parent
3c9f028c
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
53 additions
and
8 deletions
+53
-8
Facet.hs
src/Gargantext/Database/Facet.hs
+44
-2
Add.hs
src/Gargantext/Database/Node/Document/Add.hs
+6
-4
NodeNode.hs
src/Gargantext/Database/NodeNode.hs
+3
-2
No files found.
src/Gargantext/Database/Facet.hs
View file @
5efcb182
...
...
@@ -67,7 +67,9 @@ import Gargantext.Database.Config (nodeTypeId)
--instance FromJSON Facet
--instance ToJSON Facet
type
FacetDoc
=
Facet
NodeId
UTCTime
HyperdataDocument
Bool
Int
type
Favorite
=
Bool
type
FacetDoc
=
Facet
NodeId
UTCTime
HyperdataDocument
Favorite
Int
type
FacetSources
=
FacetDoc
type
FacetAuthors
=
FacetDoc
type
FacetTerms
=
FacetDoc
...
...
@@ -108,7 +110,7 @@ $(makeLensesWith abbreviatedFields ''Facet)
type
FacetDocRead
=
Facet
(
Column
PGInt4
)
(
Column
PGTimestamptz
)
(
Column
PGJsonb
)
(
Column
PGBool
)
(
Column
PGBool
)
(
Column
PGInt4
)
-----------------------------------------------------------------------
...
...
@@ -125,6 +127,46 @@ instance Arbitrary FacetChart where
-----------------------------------------------------------------------
data
OrderBy
=
DateAsc
|
DateDesc
-- | TitleAsc | TitleDesc
|
FavDesc
|
FavAsc
-- | NgramCount
viewDocuments
::
CorpusId
->
NodeTypeId
->
Query
FacetDocRead
viewDocuments
cId
ntId
=
proc
()
->
do
n
<-
queryNodeTable
-<
()
nn
<-
queryNodeNodeTable
-<
()
restrict
-<
_node_id
n
.==
nodeNode_node2_id
nn
restrict
-<
nodeNode_node1_id
nn
.==
(
pgInt4
cId
)
restrict
-<
_node_typename
n
.==
(
pgInt4
ntId
)
returnA
-<
FacetDoc
(
_node_id
n
)
(
_node_date
n
)
(
_node_hyperdata
n
)
(
nodeNode_favorite
nn
)
(
pgInt4
1
)
filterDocuments
::
(
PGOrd
date
,
PGOrd
favorite
)
=>
Maybe
Gargantext
.
Core
.
Types
.
Offset
->
Maybe
Gargantext
.
Core
.
Types
.
Limit
->
OrderBy
->
Select
(
Facet
id
(
Column
date
)
hyperdata
(
Column
favorite
)
ngramCount
)
->
Query
(
Facet
id
(
Column
date
)
hyperdata
(
Column
favorite
)
ngramCount
)
filterDocuments
o
l
order
q
=
limit'
l
$
offset'
o
$
orderBy
ordering
q
where
ordering
=
case
order
of
DateAsc
->
asc
facetDoc_created
DateDesc
->
desc
facetDoc_created
--TitleAsc -> asc facetDoc_hyperdata
--TitleDesc -> desc facetDoc_hyperdata
FavAsc
->
asc
facetDoc_favorite
FavDesc
->
desc
facetDoc_favorite
runViewDocuments
::
CorpusId
->
Maybe
Offset
->
Maybe
Limit
->
OrderBy
->
Cmd
[
FacetDoc
]
runViewDocuments
cId
o
l
order
=
mkCmd
$
\
c
->
runQuery
c
(
filterDocuments
o
l
order
$
viewDocuments
cId
ntId
)
where
ntId
=
nodeTypeId
NodeDocument
{-
getDocFacet :: Connection -> NodeType -> Int -> Maybe NodeType
-> Maybe Offset -> Maybe Limit
...
...
src/Gargantext/Database/Node/Document/Add.hs
View file @
5efcb182
...
...
@@ -64,14 +64,14 @@ add_debug pId ns = mkCmd $ \c -> formatQuery c queryAdd (Only $ Values fields in
-- | Input Tables: types of the tables
inputSqlTypes
::
[
Text
]
inputSqlTypes
=
map
DT
.
pack
[
"int4"
,
"int4"
]
inputSqlTypes
=
map
DT
.
pack
[
"int4"
,
"int4"
,
"bool"
]
-- | SQL query to add documents
-- TODO return id of added documents only
queryAdd
::
Query
queryAdd
=
[
sql
|
WITH input_rows(node1_id,node2_id) AS (?)
INSERT INTO nodes_nodes (node1_id, node2_id)
WITH input_rows(node1_id,node2_id
, favorite
) AS (?)
INSERT INTO nodes_nodes (node1_id, node2_id
, favorite
)
SELECT * FROM input_rows
ON CONFLICT (node1_id, node2_id) DO NOTHING -- on unique index
RETURNING 1
...
...
@@ -79,7 +79,7 @@ queryAdd = [sql|
|]
prepare
::
ParentId
->
[
NodeId
]
->
[
InputData
]
prepare
pId
ns
=
map
(
\
nId
->
InputData
pId
nId
)
ns
prepare
pId
ns
=
map
(
\
nId
->
InputData
pId
nId
False
)
ns
------------------------------------------------------------------------
-- * Main Types used
...
...
@@ -87,10 +87,12 @@ prepare pId ns = map (\nId -> InputData pId nId) ns
data
InputData
=
InputData
{
inNode1_id
::
NodeId
,
inNode2_id
::
NodeId
,
inNode_fav
::
Bool
}
deriving
(
Show
,
Generic
,
Typeable
)
instance
ToRow
InputData
where
toRow
inputData
=
[
toField
(
inNode1_id
inputData
)
,
toField
(
inNode2_id
inputData
)
,
toField
(
inNode_fav
inputData
)
]
src/Gargantext/Database/NodeNode.hs
View file @
5efcb182
...
...
@@ -22,6 +22,7 @@ commentary with @some markup@.
module
Gargantext.Database.NodeNode
where
import
Gargantext.Database.Node
(
Cmd
(
..
),
mkCmd
)
import
Gargantext.Prelude
import
Data.Maybe
(
Maybe
)
import
Data.Profunctor.Product.TH
(
makeAdaptorAndInstance
)
...
...
@@ -77,8 +78,8 @@ queryNodeNodeTable = queryTable nodeNodeTable
-- | not optimized (get all ngrams without filters)
node
Nodes
::
PGS
.
Connection
->
IO
[
NodeNode
]
node
Nodes
conn
=
runQuery
conn
queryNodeNodeTable
node
sNodes
::
Cmd
[
NodeNode
]
node
sNodes
=
mkCmd
$
\
c
->
runQuery
c
queryNodeNodeTable
instance
QueryRunnerColumnDefault
(
Nullable
PGInt4
)
Int
where
queryRunnerColumnDefault
=
fieldQueryRunnerColumn
...
...
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