2 Module : Gargantext.API.Count
3 Description : Server API
4 Copyright : (c) CNRS, 2017-Present
5 License : AGPL + CECILL v3
6 Maintainer : team@gargantext.org
7 Stability : experimental
10 Count API part of Gargantext.
13 {-# OPTIONS_GHC -fno-warn-name-shadowing #-}
15 {-# LANGUAGE TemplateHaskell #-}
16 {-# LANGUAGE TypeOperators #-}
17 {-# LANGUAGE DeriveAnyClass #-}
19 module Gargantext.API.Search
22 import Data.Aeson.TH (deriveJSON)
24 import Data.Text (Text)
25 import Data.Time (UTCTime)
26 import GHC.Generics (Generic)
27 import Gargantext.API.Prelude (GargServer)
28 import Gargantext.Core.Utils.Prefix (unPrefix, unPrefixSwagger)
29 import Gargantext.Database.Query.Facet
30 import Gargantext.Database.Action.Search
31 import Gargantext.Database.Admin.Types.Hyperdata (HyperdataContact)
32 import Gargantext.Database.Admin.Types.Node
33 import Gargantext.Prelude
35 import Test.QuickCheck (elements)
36 import Test.QuickCheck.Arbitrary
38 -----------------------------------------------------------------------
39 data SearchQuery = SearchQuery
43 $(deriveJSON (unPrefix "sq_") ''SearchQuery)
45 instance ToSchema SearchQuery where
46 declareNamedSchema = genericDeclareNamedSchema (unPrefixSwagger "sq_")
48 instance Arbitrary SearchQuery where
49 arbitrary = elements [SearchQuery ["electrodes"]]
51 -----------------------------------------------------------------------
52 data SearchDocResults = SearchDocResults { sdr_results :: [FacetDoc]}
54 $(deriveJSON (unPrefix "sdr_") ''SearchDocResults)
56 instance Arbitrary SearchDocResults where
57 arbitrary = SearchDocResults <$> arbitrary
59 instance ToSchema SearchDocResults where
60 declareNamedSchema = genericDeclareNamedSchema (unPrefixSwagger "sdr_")
62 data SearchPairedResults =
63 SearchPairedResults { spr_results :: [FacetPaired Int UTCTime HyperdataContact Int] }
65 $(deriveJSON (unPrefix "spr_") ''SearchPairedResults)
67 instance Arbitrary SearchPairedResults where
68 arbitrary = SearchPairedResults <$> arbitrary
70 instance ToSchema SearchPairedResults where
71 declareNamedSchema = genericDeclareNamedSchema (unPrefixSwagger "spr_")
73 -----------------------------------------------------------------------
74 -- TODO-ACCESS: CanSearch? or is it part of CanGetNode
75 -- TODO-EVENTS: No event, this is a read-only query.
76 type SearchAPI results = Summary "Search endpoint"
77 :> ReqBody '[JSON] SearchQuery
78 :> QueryParam "offset" Int
79 :> QueryParam "limit" Int
80 :> QueryParam "order" OrderBy
81 :> Post '[JSON] results
83 type SearchDocsAPI = SearchAPI SearchDocResults
84 searchDocs :: NodeId -> GargServer SearchDocsAPI
85 searchDocs nId (SearchQuery q) o l order =
86 SearchDocResults <$> searchInCorpus nId False q o l order
87 --SearchResults <$> searchInCorpusWithContacts nId q o l order
89 -----------------------------------------------------------------------
90 type SearchPairsAPI = Summary ""
92 :> Capture "annuaire" AnnuaireId
93 :> SearchAPI SearchPairedResults
94 searchPairs :: NodeId -> GargServer SearchPairsAPI
96 searchPairs pId aId (SearchQuery q) o l order =
97 SearchPairedResults <$> searchInCorpusWithContacts pId aId q o l order
99 -----------------------------------------------------------------------