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
153
Issues
153
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
95508061
Commit
95508061
authored
Jul 28, 2020
by
Alexandre Delanoë
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[API] Generics SearchQuery ok
parent
6b3ebf8d
Pipeline
#989
failed with stage
Changes
3
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
30 additions
and
27 deletions
+30
-27
Ngrams.hs
src/Gargantext/API/Ngrams.hs
+7
-7
Node.hs
src/Gargantext/API/Node.hs
+1
-1
Search.hs
src/Gargantext/API/Search.hs
+22
-19
No files found.
src/Gargantext/API/Ngrams.hs
View file @
95508061
src/Gargantext/API/Node.hs
View file @
95508061
...
...
@@ -129,7 +129,7 @@ type NodeAPI a = Get '[JSON] (Node a)
:<|>
"ngrams"
:>
TableNgramsApi
:<|>
"category"
:>
CatApi
:<|>
"search"
:>
(
Search
.
API
Search
.
SearchResult
)
:<|>
"search"
:>
(
Search
.
API
Int
)
--
Search.SearchResult)
:<|>
"share"
:>
Share
.
API
-- Pairing utilities
...
...
src/Gargantext/API/Search.hs
View file @
95508061
...
...
@@ -22,14 +22,14 @@ module Gargantext.API.Search
import
Data.Aeson
import
Data.Swagger
import
Data.Text
(
Text
)
import
Data.Time
(
UTCTime
)
--
import Data.Time (UTCTime)
import
GHC.Generics
(
Generic
)
import
Gargantext.API.Prelude
(
GargServer
)
import
Gargantext.Core.Utils.Prefix
(
unPrefixSwagger
)
import
Gargantext.Database.Query.Facet
import
Gargantext.Database.Action.Search
import
Gargantext.Database.Action.Flow.Pairing
(
isPairedWith
)
import
Gargantext.Database.Admin.Types.Hyperdata
(
HyperdataContact
)
--
import Gargantext.Database.Action.Search
--
import Gargantext.Database.Action.Flow.Pairing (isPairedWith)
--
import Gargantext.Database.Admin.Types.Hyperdata (HyperdataContact)
import
Gargantext.Database.Admin.Types.Node
import
Gargantext.Prelude
import
Servant
...
...
@@ -47,15 +47,23 @@ type API results = Summary "Search endpoint"
:>
QueryParam
"order"
OrderBy
:>
Post
'[
J
SON
]
results
-----------------------------------------------------------------------
api
::
NodeId
->
GargServer
(
API
Int
)
-- SearchResult)
api
_
_
_
_
_
=
undefined
{-
api :: NodeId -> GargServer (API SearchResult)
api nId (SearchQuery q SearchDoc) o l order =
SearchResultDoc <$> searchInCorpus nId False q o l order
api nId (SearchQuery q SearchContact) o l order = do
aIds
<-
isPairedWith
NodeAnnuaire
nId
undefined
{- aIds <- isPairedWith NodeAnnuaire nId
-- TODO if paired with several corpus
case head aIds of
Nothing -> pure $ SearchNoResult "[G.A.Search] pair corpus with an Annuaire"
Just aId -> SearchResultContact <$> searchInCorpusWithContacts nId aId q o l order
-}
-}
-----------------------------------------------------------------------
-----------------------------------------------------------------------
-- | Main Types
...
...
@@ -64,16 +72,12 @@ data SearchType = SearchDoc | SearchContact
deriving
(
Generic
)
instance
FromJSON
SearchType
{-
where
parseJSON
=
genericParseJSON
(
defaultOptions
{
sumEncoding
=
ObjectWithSingleField
})
-}
instance
ToJSON
SearchType
{-
where
toJSON
=
genericToJSON
(
defaultOptions
{
sumEncoding
=
ObjectWithSingleField
})
-}
instance
ToSchema
SearchType
instance
Arbitrary
SearchType
where
...
...
@@ -83,19 +87,17 @@ instance Arbitrary SearchType where
data
SearchQuery
=
SearchQuery
{
query
::
!
[
Text
]
,
expected
::
!
SearchType
}
deriving
(
Generic
)
}
|
SearchQueryErr
!
Text
deriving
(
Generic
)
instance
FromJSON
SearchQuery
{-
where
parseJSON
=
genericParseJSON
(
defaultOptions
{
sumEncoding
=
ObjectWithSingleField
})
-}
instance
ToJSON
SearchQuery
{-
where
toJSON
=
genericToJSON
(
defaultOptions
{
sumEncoding
=
ObjectWithSingleField
})
-}
instance
ToSchema
SearchQuery
{-
...
...
@@ -105,11 +107,12 @@ instance ToSchema SearchQuery
instance
Arbitrary
SearchQuery
where
arbitrary
=
elements
[
SearchQuery
[
"electrodes"
]
SearchDoc
]
-- arbitrary = elements [SearchQuery "electrodes" 1 ] --SearchDoc]
-----------------------------------------------------------------------
data
SearchResult
=
SearchResultDoc
{
docs
::
!
[
FacetDoc
]}
|
SearchResultContact
{
contacts
::
!
[
FacetPaired
Int
UTCTime
HyperdataContact
Int
]
}
|
SearchNoResult
{
message
::
!
Text
}
--
| SearchResultContact { contacts :: ![FacetPaired Int UTCTime HyperdataContact Int] }
--
| SearchNoResult { message :: !Text }
deriving
(
Generic
)
...
...
@@ -128,9 +131,9 @@ instance ToJSON SearchResult
instance
Arbitrary
SearchResult
where
arbitrary
=
do
srd
<-
SearchResultDoc
<$>
arbitrary
src
<-
SearchResultContact
<$>
arbitrary
srn
<-
pure
$
SearchNoResult
"No result because.."
elements
[
srd
,
src
,
srn
]
--
src <- SearchResultContact <$> arbitrary
--
srn <- pure $ SearchNoResult "No result because.."
elements
[
srd
]
--
, src, srn]
instance
ToSchema
SearchResult
where
declareNamedSchema
=
genericDeclareNamedSchema
(
unPrefixSwagger
"sr_"
)
...
...
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