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 NoImplicitPrelude #-}
16 {-# LANGUAGE DataKinds #-}
17 {-# LANGUAGE TemplateHaskell #-}
18 {-# LANGUAGE TypeOperators #-}
19 {-# LANGUAGE DeriveGeneric #-}
20 {-# LANGUAGE DeriveAnyClass #-}
21 {-# LANGUAGE OverloadedStrings #-}
22 {-# LANGUAGE RankNTypes #-}
24 module Gargantext.API.Search
27 import GHC.Generics (Generic)
28 import Data.Time (UTCTime)
29 import Data.Aeson.TH (deriveJSON)
31 import Data.Text (Text)
33 import Test.QuickCheck.Arbitrary
34 import Test.QuickCheck (elements)
35 -- import Control.Applicative ((<*>))
36 import Gargantext.API.Types (GargServer)
37 import Gargantext.Prelude
38 import Gargantext.Core.Utils.Prefix (unPrefix, unPrefixSwagger)
39 import Gargantext.Database.Types.Node
40 import Gargantext.Database.TextSearch
41 import Gargantext.Database.Facet
43 -----------------------------------------------------------------------
44 data SearchQuery = SearchQuery
48 $(deriveJSON (unPrefix "sq_") ''SearchQuery)
50 instance ToSchema SearchQuery where
51 declareNamedSchema = genericDeclareNamedSchema (unPrefixSwagger "sq_")
53 instance Arbitrary SearchQuery where
54 arbitrary = elements [SearchQuery ["electrodes"]]
56 -----------------------------------------------------------------------
57 data SearchDocResults = SearchDocResults { sdr_results :: [FacetDoc]}
59 $(deriveJSON (unPrefix "sdr_") ''SearchDocResults)
61 instance Arbitrary SearchDocResults where
62 arbitrary = SearchDocResults <$> arbitrary
64 instance ToSchema SearchDocResults where
65 declareNamedSchema = genericDeclareNamedSchema (unPrefixSwagger "sdr_")
67 data SearchPairedResults = SearchPairedResults { spr_results :: [FacetPaired Int UTCTime HyperdataDocument Int [Pair Int Text]] }
69 $(deriveJSON (unPrefix "spr_") ''SearchPairedResults)
71 instance Arbitrary SearchPairedResults where
72 arbitrary = SearchPairedResults <$> arbitrary
74 instance ToSchema SearchPairedResults where
75 declareNamedSchema = genericDeclareNamedSchema (unPrefixSwagger "spr_")
77 -----------------------------------------------------------------------
78 -- TODO-ACCESS: CanSearch? or is it part of CanGetNode
79 -- TODO-EVENTS: No event, this is a read-only query.
80 type SearchAPI results
81 = Summary "Search endpoint"
82 :> ReqBody '[JSON] SearchQuery
83 :> QueryParam "offset" Int
84 :> QueryParam "limit" Int
85 :> QueryParam "order" OrderBy
86 :> Post '[JSON] results
88 type SearchDocsAPI = SearchAPI SearchDocResults
89 type SearchPairsAPI = SearchAPI SearchPairedResults
90 -----------------------------------------------------------------------
92 searchPairs :: NodeId -> GargServer SearchPairsAPI
93 searchPairs pId (SearchQuery q) o l order =
94 SearchPairedResults <$> searchInCorpusWithContacts pId q o l order
96 searchDocs :: NodeId -> GargServer SearchDocsAPI
97 searchDocs nId (SearchQuery q) o l order =
98 SearchDocResults <$> searchInCorpus nId False q o l order
99 --SearchResults <$> searchInCorpusWithContacts nId q o l order