Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
H
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
Przemyslaw Kaminski
haskell-gargantext
Commits
1303ec82
Commit
1303ec82
authored
Dec 06, 2018
by
Alexandre Delanoë
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[API][Search][Graph] type of Author with id.
parent
9bfcc0d8
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
19 additions
and
12 deletions
+19
-12
Search.hs
src/Gargantext/API/Search.hs
+19
-12
No files found.
src/Gargantext/API/Search.hs
View file @
1303ec82
...
...
@@ -12,7 +12,6 @@ Count API part of Gargantext.
{-# OPTIONS_GHC -fno-warn-name-shadowing #-}
{-# LANGUAGE NoImplicitPrelude #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE TemplateHaskell #-}
...
...
@@ -24,28 +23,21 @@ Count API part of Gargantext.
module
Gargantext.API.Search
where
import
GHC.Generics
(
Generic
)
import
Control.Monad.IO.Class
(
liftIO
)
import
Data.Aeson
hiding
(
Error
,
fieldLabelModifier
)
import
Data.Aeson.TH
(
deriveJSON
)
import
Data.Swagger
import
Data.Text
(
Text
)
import
Database.PostgreSQL.Simple
(
Connection
)
import
Servant
import
Test.QuickCheck.Arbitrary
import
Test.QuickCheck
(
elements
)
-- import Control.Applicative ((<*>))
import
Gargantext.Prelude
import
Gargantext.Core.Utils.Prefix
(
unPrefix
)
import
Gargantext.Database.TextSearch
-----------------------------------------------------------------------
data
SearchQuery
=
SearchQuery
{
sq_query
::
[
Text
]
,
sq_parent_id
::
Int
...
...
@@ -56,19 +48,34 @@ instance ToSchema SearchQuery where
genericDeclareNamedSchema
defaultSchemaOptions
{
fieldLabelModifier
=
\
fieldLabel
->
drop
3
fieldLabel
}
instance
Arbitrary
SearchQuery
where
arbitrary
=
elements
[
SearchQuery
[
"electrodes"
]
472764
]
-----------------------------------------------------------------------
data
Author
=
Author
{
_a_name
::
Text
,
_a_id
::
Int
}
deriving
(
Generic
)
$
(
deriveJSON
(
unPrefix
"_a_"
)
''
A
uthor
)
instance
ToSchema
Author
where
declareNamedSchema
=
genericDeclareNamedSchema
defaultSchemaOptions
{
fieldLabelModifier
=
\
fieldLabel
->
drop
3
fieldLabel
}
arbitraryAuthor
::
Author
arbitraryAuthor
=
Author
"Jezequel"
1011669
instance
Arbitrary
Author
where
arbitrary
=
elements
[
arbitraryAuthor
]
-----------------------------------------------------------------------
data
SearchResult
=
SearchResult
{
sr_id
::
Int
,
sr_title
::
Text
,
sr_authors
::
Text
,
sr_authors
::
[
Author
]
}
deriving
(
Generic
)
$
(
deriveJSON
(
unPrefix
"sr_"
)
''
S
earchResult
)
instance
Arbitrary
SearchResult
where
arbitrary
=
elements
[
SearchResult
1
"Title"
"Authors"
]
arbitrary
=
elements
[
SearchResult
1
"Title"
[
arbitraryAuthor
]
]
instance
ToSchema
SearchResult
where
declareNamedSchema
=
...
...
@@ -97,7 +104,7 @@ type SearchAPI = Post '[JSON] SearchResults
search
::
Connection
->
SearchQuery
->
Handler
SearchResults
search
c
(
SearchQuery
q
pId
)
=
liftIO
$
SearchResults
<$>
map
(
\
(
i
,
_
,
t
,
_
,
a
,
_
)
->
SearchResult
i
(
cs
$
encode
t
)
(
cs
$
encode
a
)
)
liftIO
$
SearchResults
<$>
map
(
\
(
i
,
_
,
t
,
_
,
a
,
_
)
->
SearchResult
i
(
cs
$
encode
t
)
[
arbitraryAuthor
]
)
<$>
textSearch
c
(
toTSQuery
q
)
pId
5
0
Desc
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