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
154
Issues
154
List
Board
Labels
Milestones
Merge Requests
12
Merge Requests
12
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
8cdb7c22
Commit
8cdb7c22
authored
Oct 20, 2020
by
Przemyslaw Kaminski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[table] implement querystring params
Limit, offset, search string, order by.
parent
1512855c
Pipeline
#1159
failed with stage
Changes
3
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
70 additions
and
34 deletions
+70
-34
Table.hs
src/Gargantext/API/Table.hs
+38
-18
Learn.hs
src/Gargantext/Database/Action/Learn.hs
+3
-3
Facet.hs
src/Gargantext/Database/Query/Facet.hs
+29
-13
No files found.
src/Gargantext/API/Table.hs
View file @
8cdb7c22
...
...
@@ -56,6 +56,11 @@ import Gargantext.Prelude
type
TableApi
=
Summary
"Table API"
:>
QueryParam
"tabType"
TabType
:>
QueryParam
"list"
ListId
:>
QueryParam
"limit"
Int
:>
QueryParam
"offset"
Int
:>
QueryParam
"orderBy"
OrderBy
:>
QueryParam
"query"
Text
:>
Get
'[
J
SON
]
(
HashedResponse
FacetTableResult
)
:<|>
Summary
"Table API (POST)"
:>
ReqBody
'[
J
SON
]
TableQuery
...
...
@@ -90,14 +95,21 @@ tableApi id' = getTableApi id'
:<|>
getTableHashApi
id'
getTableApi
::
NodeId
->
Maybe
TabType
->
Cmd
err
(
HashedResponse
FacetTableResult
)
getTableApi
cId
tabType
=
do
t
<-
getTable
cId
tabType
Nothing
Nothing
Nothing
getTableApi
::
NodeId
->
Maybe
TabType
->
Maybe
ListId
->
Maybe
Int
->
Maybe
Int
->
Maybe
OrderBy
->
Maybe
Text
->
Cmd
err
(
HashedResponse
FacetTableResult
)
getTableApi
cId
tabType
_mListId
mLimit
mOffset
mOrderBy
mQuery
=
do
printDebug
"[getTableApi] mQuery"
mQuery
t
<-
getTable
cId
tabType
mOffset
mLimit
mOrderBy
mQuery
pure
$
constructHashedResponse
t
postTableApi
::
NodeId
->
TableQuery
->
Cmd
err
FacetTableResult
postTableApi
cId
(
TableQuery
o
l
order
ft
""
)
=
getTable
cId
(
Just
ft
)
(
Just
o
)
(
Just
l
)
(
Just
order
)
postTableApi
cId
(
TableQuery
o
l
order
ft
""
)
=
getTable
cId
(
Just
ft
)
(
Just
o
)
(
Just
l
)
(
Just
order
)
Nothing
postTableApi
cId
(
TableQuery
o
l
order
ft
q
)
=
case
ft
of
Docs
->
searchInCorpus'
cId
False
[
q
]
(
Just
o
)
(
Just
l
)
(
Just
order
)
Trash
->
searchInCorpus'
cId
True
[
q
]
(
Just
o
)
(
Just
l
)
(
Just
order
)
...
...
@@ -105,7 +117,7 @@ postTableApi cId (TableQuery o l order ft q) = case ft of
getTableHashApi
::
NodeId
->
Maybe
TabType
->
Cmd
err
Text
getTableHashApi
cId
tabType
=
do
HashedResponse
{
hash
=
h
}
<-
getTableApi
cId
tabType
HashedResponse
{
hash
=
h
}
<-
getTableApi
cId
tabType
Nothing
Nothing
Nothing
Nothing
Nothing
pure
h
searchInCorpus'
::
CorpusId
...
...
@@ -121,21 +133,29 @@ searchInCorpus' cId t q o l order = do
pure
$
TableResult
{
tr_docs
=
docs
,
tr_count
=
countAllDocs
}
getTable
::
NodeId
->
Maybe
TabType
->
Maybe
Offset
->
Maybe
Limit
->
Maybe
OrderBy
->
Cmd
err
FacetTableResult
getTable
cId
ft
o
l
order
=
do
docs
<-
getTable'
cId
ft
o
l
order
docsCount
<-
runCountDocuments
cId
(
if
ft
==
Just
Trash
then
True
else
False
)
getTable
::
NodeId
->
Maybe
TabType
->
Maybe
Offset
->
Maybe
Limit
->
Maybe
OrderBy
->
Maybe
Text
->
Cmd
err
FacetTableResult
getTable
cId
ft
o
l
order
query
=
do
docs
<-
getTable'
cId
ft
o
l
order
query
docsCount
<-
runCountDocuments
cId
(
if
ft
==
Just
Trash
then
True
else
False
)
query
pure
$
TableResult
{
tr_docs
=
docs
,
tr_count
=
docsCount
}
getTable'
::
NodeId
->
Maybe
TabType
->
Maybe
Offset
->
Maybe
Limit
->
Maybe
OrderBy
->
Cmd
err
[
FacetDoc
]
getTable'
cId
ft
o
l
order
=
getTable'
::
NodeId
->
Maybe
TabType
->
Maybe
Offset
->
Maybe
Limit
->
Maybe
OrderBy
->
Maybe
Text
->
Cmd
err
[
FacetDoc
]
getTable'
cId
ft
o
l
order
query
=
case
ft
of
(
Just
Docs
)
->
runViewDocuments
cId
False
o
l
order
(
Just
Trash
)
->
runViewDocuments
cId
True
o
l
order
(
Just
Docs
)
->
runViewDocuments
cId
False
o
l
order
query
(
Just
Trash
)
->
runViewDocuments
cId
True
o
l
order
query
(
Just
MoreFav
)
->
moreLike
cId
o
l
order
IsFav
(
Just
MoreTrash
)
->
moreLike
cId
o
l
order
IsTrash
x
->
panic
$
"not implemented in getTable: "
<>
(
cs
$
show
x
)
...
...
src/Gargantext/Database/Action/Learn.hs
View file @
8cdb7c22
...
...
@@ -42,10 +42,10 @@ getPriors :: FavOrTrash -> CorpusId -> Cmd err (Events Bool)
getPriors
ft
cId
=
do
docs_fav
<-
filter
(
\
(
FacetDoc
_
_
_
_
f
_
)
->
f
==
Just
2
)
<$>
runViewDocuments
cId
False
Nothing
Nothing
Nothing
<$>
runViewDocuments
cId
False
Nothing
Nothing
Nothing
Nothing
docs_trash
<-
List
.
take
(
List
.
length
docs_fav
)
<$>
runViewDocuments
cId
True
Nothing
Nothing
Nothing
<$>
runViewDocuments
cId
True
Nothing
Nothing
Nothing
Nothing
let
priors
=
priorEventsWith
text
(
fav2bool
ft
)
(
List
.
zip
(
repeat
False
)
docs_fav
...
...
@@ -59,7 +59,7 @@ moreLikeWith :: CorpusId -> Maybe Offset -> Maybe Limit -> Maybe OrderBy
moreLikeWith
cId
o
l
order
ft
priors
=
do
docs_test
<-
filter
(
\
(
FacetDoc
_
_
_
_
f
_
)
->
f
==
Just
1
)
<$>
runViewDocuments
cId
False
o
Nothing
order
<$>
runViewDocuments
cId
False
o
Nothing
order
Nothing
let
results
=
map
fst
$
filter
((
==
)
(
Just
$
not
$
fav2bool
ft
)
.
snd
)
...
...
src/Gargantext/Database/Query/Facet.hs
View file @
8cdb7c22
...
...
@@ -42,13 +42,11 @@ import Data.Aeson (FromJSON, ToJSON)
import
Data.Aeson.TH
(
deriveJSON
)
import
Data.Profunctor.Product.TH
(
makeAdaptorAndInstance
)
import
Data.Swagger
import
Data.Text
(
Text
)
import
qualified
Data.Text
as
T
import
Data.Time
(
UTCTime
)
import
Data.Time.Segment
(
jour
)
import
Data.Typeable
(
Typeable
)
import
GHC.Generics
(
Generic
)
import
Opaleye
import
Pr
elude
hiding
(
null
,
id
,
map
,
sum
,
not
,
read
)
import
Pr
otolude
hiding
(
null
,
map
,
sum
,
not
)
import
Servant.API
import
Test.QuickCheck
(
elements
)
import
Test.QuickCheck.Arbitrary
...
...
@@ -276,19 +274,32 @@ queryAuthorsDoc = leftJoin5 queryNodeTable queryNodeNodeNgramsTable queryNgramsT
------------------------------------------------------------------------
-- TODO-SECURITY check
runViewDocuments
::
CorpusId
->
IsTrash
->
Maybe
Offset
->
Maybe
Limit
->
Maybe
OrderBy
->
Cmd
err
[
FacetDoc
]
runViewDocuments
cId
t
o
l
order
=
runOpaQuery
$
filterWith
o
l
order
$
viewDocuments
cId
t
ntId
runViewDocuments
::
CorpusId
->
IsTrash
->
Maybe
Offset
->
Maybe
Limit
->
Maybe
OrderBy
->
Maybe
Text
->
Cmd
err
[
FacetDoc
]
runViewDocuments
cId
t
o
l
order
query
=
do
runOpaQuery
$
filterWith
o
l
order
sqlQuery
where
ntId
=
nodeTypeId
NodeDocument
sqlQuery
=
viewDocuments
cId
t
ntId
query
runCountDocuments
::
CorpusId
->
IsTrash
->
Cmd
err
Int
runCountDocuments
cId
t
=
runCountOpaQuery
$
viewDocuments
cId
t
$
nodeTypeId
NodeDocument
runCountDocuments
::
CorpusId
->
IsTrash
->
Maybe
Text
->
Cmd
err
Int
runCountDocuments
cId
t
mQuery
=
do
runCountOpaQuery
sqlQuery
where
sqlQuery
=
viewDocuments
cId
t
(
nodeTypeId
NodeDocument
)
mQuery
viewDocuments
::
CorpusId
->
IsTrash
->
NodeTypeId
->
Query
FacetDocRead
viewDocuments
cId
t
ntId
=
proc
()
->
do
viewDocuments
::
CorpusId
->
IsTrash
->
NodeTypeId
->
Maybe
Text
->
Query
FacetDocRead
viewDocuments
cId
t
ntId
mQuery
=
proc
()
->
do
n
<-
queryNodeTable
-<
()
nn
<-
queryNodeNodeTable
-<
()
restrict
-<
n
^.
node_id
.==
nn
^.
nn_node2_id
...
...
@@ -296,6 +307,11 @@ viewDocuments cId t ntId = proc () -> do
restrict
-<
n
^.
node_typename
.==
(
pgInt4
ntId
)
restrict
-<
if
t
then
nn
^.
nn_category
.==
(
pgInt4
0
)
else
nn
^.
nn_category
.>=
(
pgInt4
1
)
let
query
=
(
fromMaybe
""
mQuery
)
iLikeQuery
=
T
.
intercalate
""
[
"%"
,
query
,
"%"
]
restrict
-<
(
n
^.
node_name
)
`
ilike
`
(
pgStrictText
iLikeQuery
)
returnA
-<
FacetDoc
(
_node_id
n
)
(
_node_date
n
)
(
_node_name
n
)
...
...
@@ -305,7 +321,7 @@ viewDocuments cId t ntId = proc () -> do
------------------------------------------------------------------------
filterWith
::
(
PGOrd
date
,
PGOrd
title
,
PGOrd
score
,
hyperdata
~
Column
SqlJsonb
)
=>
Maybe
Gargantext
.
Core
.
Types
.
Offset
Maybe
Gargantext
.
Core
.
Types
.
Offset
->
Maybe
Gargantext
.
Core
.
Types
.
Limit
->
Maybe
OrderBy
->
Select
(
Facet
id
(
Column
date
)
(
Column
title
)
hyperdata
(
Column
score
)
ngramCount
)
...
...
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