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