Commit 424d20ee authored by Alexandre Delanoë's avatar Alexandre Delanoë

[SEARCH] and create corpus

parent c3fc3946
...@@ -425,3 +425,7 @@ startGargantextMock port = do ...@@ -425,3 +425,7 @@ startGargantextMock port = do
application <- makeMockApp . MockEnv $ FireWall False application <- makeMockApp . MockEnv $ FireWall False
run port application run port application
-} -}
...@@ -18,20 +18,49 @@ New corpus means either: ...@@ -18,20 +18,49 @@ New corpus means either:
{-# LANGUAGE DataKinds #-} {-# LANGUAGE DataKinds #-}
{-# LANGUAGE TypeOperators #-} {-# LANGUAGE TypeOperators #-}
{-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE RankNTypes #-}
module Gargantext.API.Corpus.New module Gargantext.API.Corpus.New
where where
import Servant import Data.Aeson.TH (deriveJSON)
import Gargantext.Prelude import Data.Swagger
import Gargantext.API.Count (Query(..)) import Data.Text (Text)
import GHC.Generics (Generic)
import Gargantext.Core (Lang(..))
import Gargantext.Core.Utils.Prefix (unPrefix)
import Gargantext.Database.Flow (flowCorpusSearchInDatabase)
import Gargantext.Database.Types.Node (CorpusId) import Gargantext.Database.Types.Node (CorpusId)
--import Gargantext.Database.Flow (flowCorpusSearchInDatabase) import Gargantext.Prelude
import Servant
import Test.QuickCheck (elements)
import Test.QuickCheck.Arbitrary
import Gargantext.Database.Flow (FlowCmdM)
data Query = Query { query_query :: Text
, query_corpus_id :: Int
}
deriving (Eq, Show, Generic)
deriveJSON (unPrefix "query_") ''Query
instance Arbitrary Query where
arbitrary = elements [ Query q n
| q <- ["a","b"]
, n <- [0..10]
]
instance ToSchema Query
type Api = Summary "New Corpus endpoint" type Api = Summary "New Corpus endpoint"
:> ReqBody '[JSON] Query :> ReqBody '[JSON] Query
:> Post '[JSON] CorpusId :> Post '[JSON] CorpusId
api :: Monad m => Query -> m CorpusId api :: FlowCmdM env err m => Query -> m CorpusId
api _ = pure 1 api (Query q _) = do
cId <- flowCorpusSearchInDatabase "user1" EN q
pure cId
...@@ -119,13 +119,22 @@ flowCorpusFile u n l la ff fp = do ...@@ -119,13 +119,22 @@ flowCorpusFile u n l la ff fp = do
flowCorpus u n la (map (map toHyperdataDocument) docs) flowCorpus u n la (map (map toHyperdataDocument) docs)
-- TODO query with complex query -- TODO query with complex query
flowCorpusSearchInDatabase :: FlowCmdM env ServantErr m flowCorpusSearchInDatabase :: FlowCmdM env err m
=> Username -> Lang -> Text -> m CorpusId => Username -> Lang -> Text -> m CorpusId
flowCorpusSearchInDatabase u la q = do flowCorpusSearchInDatabase u la q = do
(_masterUserId, _masterRootId, cId) <- getOrMkRootWithCorpus userMaster "" (Nothing :: Maybe HyperdataCorpus) (_masterUserId, _masterRootId, cId) <- getOrMkRootWithCorpus userMaster "" (Nothing :: Maybe HyperdataCorpus)
ids <- map fst <$> searchInDatabase cId (stemIt q) ids <- map fst <$> searchInDatabase cId (stemIt q)
flowCorpusUser la u q (Nothing :: Maybe HyperdataCorpus) ids flowCorpusUser la u q (Nothing :: Maybe HyperdataCorpus) ids
flowCorpusSearchInDatabase' :: FlowCmdM env ServantErr m
=> Username -> Lang -> Text -> m CorpusId
flowCorpusSearchInDatabase' u la q = do
(_masterUserId, _masterRootId, cId) <- getOrMkRootWithCorpus userMaster "" (Nothing :: Maybe HyperdataCorpus)
ids <- map fst <$> searchInDatabase cId (stemIt q)
flowCorpusUser la u q (Nothing :: Maybe HyperdataCorpus) ids
------------------------------------------------------------------------ ------------------------------------------------------------------------
flow :: (FlowCmdM env ServantErr m, FlowCorpus a, MkCorpus c) flow :: (FlowCmdM env ServantErr m, FlowCorpus a, MkCorpus c)
...@@ -139,7 +148,7 @@ flowCorpus :: (FlowCmdM env ServantErr m, FlowCorpus a) ...@@ -139,7 +148,7 @@ flowCorpus :: (FlowCmdM env ServantErr m, FlowCorpus a)
flowCorpus = flow (Nothing :: Maybe HyperdataCorpus) flowCorpus = flow (Nothing :: Maybe HyperdataCorpus)
flowCorpusUser :: (FlowCmdM env ServantErr m, MkCorpus c) flowCorpusUser :: (FlowCmdM env err m, MkCorpus c)
=> Lang -> Username -> CorpusName -> Maybe c -> [NodeId] -> m CorpusId => Lang -> Username -> CorpusName -> Maybe c -> [NodeId] -> m CorpusId
flowCorpusUser l userName corpusName ctype ids = do flowCorpusUser l userName corpusName ctype ids = do
-- User Flow -- User Flow
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment