Commit d329decd authored by Przemyslaw Kaminski's avatar Przemyslaw Kaminski

[document export] this works now, in JSON format

parent e5bb3ecc
Pipeline #2301 passed with stage
in 18 minutes and 51 seconds
...@@ -15,25 +15,47 @@ import qualified Data.Text as T ...@@ -15,25 +15,47 @@ import qualified Data.Text as T
import Data.Version (showVersion) import Data.Version (showVersion)
import Gargantext.API.Node.Document.Export.Types import Gargantext.API.Node.Document.Export.Types
import Gargantext.API.Prelude (GargNoServer) import Gargantext.API.Prelude (GargNoServer)
import Gargantext.Core (toDBid)
import Gargantext.Core.Types import Gargantext.Core.Types
-- import Gargantext.Database.Admin.Types.Hyperdata (HyperdataDocument(..)) -- import Gargantext.Database.Admin.Types.Hyperdata (HyperdataDocument(..))
import Gargantext.Database.Query.Table.Node (getDocumentsWithParentId) import Gargantext.Database.Query.Facet (runViewDocuments, Facet(..))
import Gargantext.Database.Query.Table.Node (getClosestParentIdByType)
import Gargantext.Database.Schema.Node (NodePoly(..))
import Gargantext.Prelude import Gargantext.Prelude
import qualified Paths_gargantext as PG -- cabal magic build module import qualified Paths_gargantext as PG -- cabal magic build module
-- import Servant (Proxy(..)) -- import Servant (Proxy(..))
-------------------------------------------------- --------------------------------------------------
-- | Hashes are ordered by Set -- | Hashes are ordered by Set
getDocuments :: DocId getDocuments :: UserId
-> DocId
-> GargNoServer DocumentExport -> GargNoServer DocumentExport
getDocuments pId = do getDocuments uId pId = do
printDebug "[getDocuments] pId" pId printDebug "[getDocuments] pId" pId
docs <- getDocumentsWithParentId pId -- NodeDocument (Proxy :: Proxy HyperdataDocument) mcId <- getClosestParentIdByType pId NodeCorpus
let cId = maybe (panic "[G.A.N.D.Export] Node has no parent") identity mcId
printDebug "[getDocuments] cId" cId
--docs <- getDocumentsWithParentId cId -- NodeDocument (Proxy :: Proxy HyperdataDocument)
docs <- runViewDocuments cId False Nothing Nothing Nothing Nothing
printDebug "[getDocuments] got docs" docs printDebug "[getDocuments] got docs" docs
pure $ DocumentExport { _de_documents = mapDoc <$> docs --de_docs <- mapM mapFacetDoc docs
pure $ DocumentExport { _de_documents = mapFacetDoc <$> docs
, _de_garg_version = T.pack $ showVersion PG.version } , _de_garg_version = T.pack $ showVersion PG.version }
where where
mapDoc d = Document { _d_document = d mapFacetDoc (FacetDoc { .. }) =
, _d_ngrams = Ngrams { _ng_ngrams = [] Document { _d_document =
, _ng_hash = "" } Node { _node_id = facetDoc_id
, _d_hash = ""} , _node_hash_id = Nothing
, _node_typename = toDBid NodeDocument
, _node_user_id = uId
, _node_parent_id = Nothing
, _node_name = facetDoc_title
, _node_date = facetDoc_created
, _node_hyperdata = facetDoc_hyperdata }
, _d_ngrams = Ngrams { _ng_ngrams = []
, _ng_hash = "" }
, _d_hash = "" }
_mapDoc d = Document { _d_document = d
, _d_ngrams = Ngrams { _ng_ngrams = []
, _ng_hash = "" }
, _d_hash = ""}
...@@ -230,7 +230,7 @@ serverPrivateGargAPI' (AuthenticatedUser (NodeId uid)) ...@@ -230,7 +230,7 @@ serverPrivateGargAPI' (AuthenticatedUser (NodeId uid))
:<|> withAccess (Proxy :: Proxy TableNgramsApi) Proxy uid :<|> withAccess (Proxy :: Proxy TableNgramsApi) Proxy uid
<$> PathNode <*> apiNgramsTableDoc <$> PathNode <*> apiNgramsTableDoc
:<|> DocumentExport.getDocuments :<|> DocumentExport.getDocuments uid
:<|> count -- TODO: undefined :<|> count -- TODO: undefined
......
...@@ -21,6 +21,7 @@ Portability : POSIX ...@@ -21,6 +21,7 @@ Portability : POSIX
module Gargantext.Database.Query.Facet module Gargantext.Database.Query.Facet
( runViewAuthorsDoc ( runViewAuthorsDoc
, runViewDocuments , runViewDocuments
, viewDocuments'
, runCountDocuments , runCountDocuments
, filterWith , filterWith
...@@ -40,7 +41,7 @@ module Gargantext.Database.Query.Facet ...@@ -40,7 +41,7 @@ module Gargantext.Database.Query.Facet
) )
where where
import Control.Arrow (returnA) import Control.Arrow (returnA, (>>>))
import Control.Lens ((^.)) import Control.Lens ((^.))
import Data.Aeson (FromJSON, ToJSON) import Data.Aeson (FromJSON, ToJSON)
import Data.Aeson.TH (deriveJSON) import Data.Aeson.TH (deriveJSON)
...@@ -272,13 +273,13 @@ viewAuthorsDoc cId _ nt = proc () -> do ...@@ -272,13 +273,13 @@ viewAuthorsDoc cId _ nt = proc () -> do
restrict -< _node_id contact' .== (toNullable $ pgNodeId cId) restrict -< _node_id contact' .== (toNullable $ pgNodeId cId)
restrict -< _node_typename doc .== (sqlInt4 $ toDBid nt) restrict -< _node_typename doc .== (sqlInt4 $ toDBid nt)
returnA -< FacetDoc (_node_id doc) returnA -< FacetDoc { facetDoc_id = _node_id doc
(_node_date doc) , facetDoc_created = _node_date doc
(_node_name doc) , facetDoc_title = _node_name doc
(_node_hyperdata doc) , facetDoc_hyperdata = _node_hyperdata doc
(toNullable $ sqlInt4 1) , facetDoc_category = toNullable $ sqlInt4 1
(toNullable $ pgDouble 1) , facetDoc_ngramCount = toNullable $ pgDouble 1
(toNullable $ pgDouble 1) , facetDoc_score = toNullable $ pgDouble 1 }
queryAuthorsDoc :: Query (NodeRead, (NodeNodeNgramsReadNull, (NgramsReadNull, (NodeNodeNgramsReadNull, NodeReadNull)))) queryAuthorsDoc :: Query (NodeRead, (NodeNodeNgramsReadNull, (NgramsReadNull, (NodeNodeNgramsReadNull, NodeReadNull))))
queryAuthorsDoc = leftJoin5 queryNodeTable queryNodeNodeNgramsTable queryNgramsTable queryNodeNodeNgramsTable queryNodeTable cond12 cond23 cond34 cond45 queryAuthorsDoc = leftJoin5 queryNodeTable queryNodeNodeNgramsTable queryNgramsTable queryNodeNodeNgramsTable queryNodeTable cond12 cond23 cond34 cond45
...@@ -346,8 +347,36 @@ viewDocuments :: CorpusId ...@@ -346,8 +347,36 @@ viewDocuments :: CorpusId
-> NodeTypeId -> NodeTypeId
-> Maybe Text -> Maybe Text
-> Query FacetDocRead -> Query FacetDocRead
viewDocuments cId t ntId mQuery = proc () -> do viewDocuments cId t ntId mQuery = viewDocumentsQuery cId t ntId mQuery >>> proc (n, nn) -> do
--n <- queryNodeTable -< () returnA -< FacetDoc { facetDoc_id = _ns_id n
, facetDoc_created = _ns_date n
, facetDoc_title = _ns_name n
, facetDoc_hyperdata = _ns_hyperdata n
, facetDoc_category = toNullable $ nn^.nn_category
, facetDoc_ngramCount = toNullable $ nn^.nn_score
, facetDoc_score = toNullable $ nn^.nn_score }
viewDocuments' :: CorpusId
-> IsTrash
-> NodeTypeId
-> Maybe Text
-> Query NodeRead
viewDocuments' cId t ntId mQuery = viewDocumentsQuery cId t ntId mQuery >>> proc (n, _nn) -> do
returnA -< Node { _node_id = _ns_id n
, _node_hash_id = ""
, _node_typename = _ns_typename n
, _node_user_id = _ns_user_id n
, _node_parent_id = -1
, _node_name = _ns_name n
, _node_date = _ns_date n
, _node_hyperdata = _ns_hyperdata n }
viewDocumentsQuery :: CorpusId
-> IsTrash
-> NodeTypeId
-> Maybe Text
-> Query (NodeSearchRead, NodeNodeRead)
viewDocumentsQuery cId t ntId mQuery = proc () -> do
n <- queryNodeSearchTable -< () n <- queryNodeSearchTable -< ()
nn <- queryNodeNodeTable -< () nn <- queryNodeNodeTable -< ()
restrict -< n^.ns_id .== nn^.nn_node2_id restrict -< n^.ns_id .== nn^.nn_node2_id
...@@ -363,14 +392,8 @@ viewDocuments cId t ntId mQuery = proc () -> do ...@@ -363,14 +392,8 @@ viewDocuments cId t ntId mQuery = proc () -> do
then pgBool True then pgBool True
--else (n^.ns_search) @@ (pgTSQuery (T.unpack query)) --else (n^.ns_search) @@ (pgTSQuery (T.unpack query))
else (n^.ns_search) @@ (plaintoTSQuery $ T.unpack query) else (n^.ns_search) @@ (plaintoTSQuery $ T.unpack query)
returnA -< FacetDoc (_ns_id n) returnA -< (n, nn)
(_ns_date n)
(_ns_name n)
(_ns_hyperdata n)
(toNullable $ nn^.nn_category)
(toNullable $ nn^.nn_score)
(toNullable $ nn^.nn_score)
------------------------------------------------------------------------ ------------------------------------------------------------------------
filterWith :: (SqlOrd date, SqlOrd title, SqlOrd category, SqlOrd score, hyperdata ~ Column SqlJsonb) => filterWith :: (SqlOrd date, SqlOrd title, SqlOrd category, SqlOrd score, hyperdata ~ Column SqlJsonb) =>
......
...@@ -180,7 +180,7 @@ getChildrenByType nId nType = do ...@@ -180,7 +180,7 @@ getChildrenByType nId nType = do
query = [sql| query = [sql|
SELECT n.id, n.typename SELECT n.id, n.typename
FROM nodes n FROM nodes n
WHERE n.parent_id = ? AND 0 = ?; WHERE n.parent_id = ? AND 0 = ?;
|] |]
------------------------------------------------------------------------ ------------------------------------------------------------------------
......
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