Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
I
istex
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
1
Issues
1
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
gargantext
crawlers
istex
Commits
a4a6fb6a
Commit
a4a6fb6a
authored
Dec 22, 2021
by
Przemyslaw Kaminski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[scroll] implement getMetadataScroll
parent
fad7b60b
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
75 additions
and
8 deletions
+75
-8
ISTEX.hs
src/ISTEX.hs
+46
-4
Client.hs
src/ISTEX/Client.hs
+29
-4
No files found.
src/ISTEX.hs
View file @
a4a6fb6a
...
...
@@ -20,13 +20,55 @@ getMetadataWith q n = do
n
(
Just
q
)
getMetadataScrollWith
::
Text
->
Maybe
Text
->
IO
(
Either
ClientError
Documents
)
getMetadataScrollWith
q
n
=
do
runIstexAPIClient
$
type
Progress
=
ScrollResponse
->
IO
()
type
ErrorHandler
=
ClientError
->
IO
()
runIstexScrollAPIClient
::
ClientM
(
ScrollResponse
)
->
IO
(
Either
ClientError
ScrollResponse
)
runIstexScrollAPIClient
cmd
=
do
manager'
<-
newManager
tlsManagerSettings
runClientM
cmd
(
mkClientEnv
manager'
$
BaseUrl
Https
"api.istex.fr"
443
"document"
)
maxScrollPages
::
Int
maxScrollPages
=
10
getMetadataScroll
::
Text
->
Text
->
Maybe
Text
->
Int
->
IO
(
Either
ClientError
Documents
)
getMetadataScroll
q
scroll
scrollId
page
=
do
if
page
>=
maxScrollPages
then
pure
$
Right
mempty
else
do
-- Prelude.putStrLn $ "[getMetadataScroll] scroll: " <> show scroll
-- Prelude.putStrLn $ "[getMetadataScroll] scrollId: " <> show scrollId
-- Prelude.putStrLn $ "[getMetadataScroll] page: " <> show page
eRes
<-
runIstexScrollAPIClient
$
searchScroll
(
Just
"author,title,abstract,publicationDate,refBibs"
)
scroll
(
Just
q
)
scrollId
case
eRes
of
Left
err
->
pure
$
Left
err
Right
res
@
(
ScrollResponse
{
..
})
->
do
eDocs
<-
getMetadataScroll
q
scroll
(
Just
_scroll_scrollId
)
(
page
+
1
)
case
eDocs
of
Left
err
->
pure
$
Left
err
Right
docs
->
pure
$
Right
$
_scroll_documents
<>
docs
--mappend _scroll_documents <*> getMetadataScroll q scroll (Just _scroll_scrollId) (page + 1)
getMetadataScrollProgress
::
Text
->
Text
->
Maybe
Text
->
Progress
->
ErrorHandler
->
IO
()
getMetadataScrollProgress
q
scroll
scrollId
progress
errorHandler
=
do
eRes
<-
runIstexScrollAPIClient
$
searchScroll
(
Just
"author,title,abstract,publicationDate,refBibs"
)
n
scroll
(
Just
q
)
scrollId
case
eRes
of
Left
err
->
errorHandler
err
Right
res
@
(
ScrollResponse
{
_scroll_noMoreScrollResults
,
_scroll_nextScrollURI
,
_scroll_scrollId
})
->
do
progress
res
getMetadataScrollProgress
q
scroll
(
Just
_scroll_scrollId
)
progress
errorHandler
type
Query
=
Text
...
...
src/ISTEX/Client.hs
View file @
a4a6fb6a
...
...
@@ -76,10 +76,34 @@ data Documents = Documents
,
_documents_hits
::
[
Document
]
}
deriving
(
Show
,
Generic
)
L
.
makeLenses
''
D
ocuments
instance
FromJSON
Documents
where
parseJSON
(
Object
o
)
=
Documents
<$>
(
o
.:
"total"
)
<*>
(
o
.:
"hits"
)
instance
Semigroup
Documents
where
(
<>
)
(
Documents
{
_documents_total
,
_documents_hits
=
d1
})
(
Documents
{
_documents_hits
=
d2
})
=
Documents
{
_documents_total
,
_documents_hits
=
d1
<>
d2
}
instance
Monoid
Documents
where
mempty
=
Documents
{
_documents_total
=
0
,
_documents_hits
=
[]
}
data
ScrollResponse
=
ScrollResponse
{
_scroll_documents
::
Documents
,
_scroll_noMoreScrollResults
::
Bool
,
_scroll_nextScrollURI
::
T
.
Text
,
_scroll_scrollId
::
T
.
Text
}
L
.
makeLenses
''
S
crollResponse
instance
FromJSON
ScrollResponse
where
parseJSON
(
Object
o
)
=
do
_documents_total
<-
o
.:
"total"
_documents_hits
<-
o
.:
"hits"
_scroll_noMoreScrollResults
<-
o
.:
"noMoreScrollResults"
_scroll_nextScrollURI
<-
o
.:
"nextScrollURI"
_scroll_scrollId
<-
o
.:
"scrollId"
pure
$
ScrollResponse
{
_scroll_documents
=
Documents
{
..
}
,
..
}
type
ISTEXAPI
=
Search
...
...
@@ -97,10 +121,11 @@ search = client istexProxy
type
SearchScroll
=
QueryParam
"output"
T
.
Text
:>
QueryParam
"scroll"
T
.
Text
:>
QueryParam
"q"
T
.
Text
:>
Get
'[
J
SON
]
Documents
:>
QueryParam
"scrollId"
T
.
Text
:>
Get
'[
J
SON
]
ScrollResponse
istexProxyScroll
::
Proxy
SearchScroll
istexProxyScroll
=
Proxy
searchScroll
::
Maybe
T
.
Text
->
Maybe
T
.
Text
->
Maybe
T
.
Text
->
ClientM
Documents
searchScroll
=
client
istexProxyScroll
searchScroll
::
Maybe
T
.
Text
->
T
.
Text
->
Maybe
T
.
Text
->
Maybe
T
.
Text
->
ClientM
ScrollResponse
searchScroll
output
scroll
=
client
istexProxyScroll
output
(
Just
scroll
)
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