, runCountDocuments
, filterWith
+ , Category
+ , Score
+ , Title
+
, Pair(..)
, Facet(..)
, FacetDoc
import Test.QuickCheck.Arbitrary
import qualified Opaleye.Internal.Unpackspec()
+import Gargantext.Core
import Gargantext.Core.Types
import Gargantext.Core.Utils.Prefix (unPrefix, unPrefixSwagger, wellNamedSchema)
-import Gargantext.Database.Admin.Config (nodeTypeId)
import Gargantext.Database.Admin.Types.Hyperdata
import Gargantext.Database.Query.Filter
import Gargantext.Database.Query.Join (leftJoin5)
--instance ToJSON Facet
type Category = Int
+type Score = Double
type Title = Text
-- TODO remove Title
-type FacetDoc = Facet NodeId UTCTime Title HyperdataDocument (Maybe Category) (Maybe Double) (Maybe Double)
+type FacetDoc = Facet NodeId UTCTime Title HyperdataDocument (Maybe Category) (Maybe Double) (Maybe Score)
-- type FacetSources = FacetDoc
-- type FacetAuthors = FacetDoc
-- type FacetTerms = FacetDoc
-- TODO-SECURITY check
--{-
-runViewAuthorsDoc :: ContactId -> IsTrash -> Maybe Offset -> Maybe Limit -> Maybe OrderBy -> Cmd err [FacetDoc]
+runViewAuthorsDoc :: HasDBid NodeType
+ => ContactId
+ -> IsTrash
+ -> Maybe Offset
+ -> Maybe Limit
+ -> Maybe OrderBy
+ -> Cmd err [FacetDoc]
runViewAuthorsDoc cId t o l order = runOpaQuery $ filterWith o l order $ viewAuthorsDoc cId t ntId
where
ntId = NodeDocument
-- TODO add delete ?
-viewAuthorsDoc :: ContactId -> IsTrash -> NodeType -> Query FacetDocRead
+viewAuthorsDoc :: HasDBid NodeType
+ => ContactId
+ -> IsTrash
+ -> NodeType
+ -> Query FacetDocRead
viewAuthorsDoc cId _ nt = proc () -> do
(doc,(_,(_,(_,contact')))) <- queryAuthorsDoc -< ()
-}
restrict -< _node_id contact' .== (toNullable $ pgNodeId cId)
- restrict -< _node_typename doc .== (pgInt4 $ nodeTypeId nt)
+ restrict -< _node_typename doc .== (pgInt4 $ toDBid nt)
returnA -< FacetDoc (_node_id doc)
(_node_date doc)
------------------------------------------------------------------------
-- TODO-SECURITY check
-runViewDocuments :: CorpusId
+runViewDocuments :: HasDBid NodeType
+ => CorpusId
-> IsTrash
-> Maybe Offset
-> Maybe Limit
runViewDocuments cId t o l order query = do
runOpaQuery $ filterWith o l order sqlQuery
where
- ntId = nodeTypeId NodeDocument
+ ntId = toDBid NodeDocument
sqlQuery = viewDocuments cId t ntId query
-runCountDocuments :: CorpusId -> IsTrash -> Maybe Text -> Cmd err Int
+runCountDocuments :: HasDBid NodeType => CorpusId -> IsTrash -> Maybe Text -> Cmd err Int
runCountDocuments cId t mQuery = do
runCountOpaQuery sqlQuery
where
- sqlQuery = viewDocuments cId t (nodeTypeId NodeDocument) mQuery
+ sqlQuery = viewDocuments cId t (toDBid NodeDocument) mQuery
viewDocuments :: CorpusId
filterWith o l order q = limit' l $ offset' o $ orderBy (orderWith order) q
-orderWith :: (PGOrd b1, PGOrd b2, PGOrd b3)
+orderWith :: (PGOrd b1, PGOrd b2, PGOrd b3, PGOrd b4)
=> Maybe OrderBy
- -> Order (Facet id (Column b1) (Column b2) (Column SqlJsonb) (Column b3) ngramCount score)
+ -> Order (Facet id (Column b1) (Column b2) (Column SqlJsonb) (Column b3) ngramCount (Column b4))
orderWith (Just DateAsc) = asc facetDoc_created
orderWith (Just DateDesc) = desc facetDoc_created
orderWith (Just TitleAsc) = asc facetDoc_title
orderWith (Just TitleDesc) = desc facetDoc_title
-orderWith (Just ScoreAsc) = asc facetDoc_category
-orderWith (Just ScoreDesc) = desc facetDoc_category
+orderWith (Just ScoreAsc) = asc facetDoc_score
+orderWith (Just ScoreDesc) = descNullsLast facetDoc_score
orderWith (Just SourceAsc) = asc facetDoc_source
orderWith (Just SourceDesc) = desc facetDoc_source