[ngrams] some attempts at making aggregation work

However, this still returns 0s for some reason.
parent 9dd4e321
...@@ -19,7 +19,7 @@ module Gargantext.Database.Query.Facet ...@@ -19,7 +19,7 @@ module Gargantext.Database.Query.Facet
( runViewAuthorsDoc ( runViewAuthorsDoc
, runViewDocuments , runViewDocuments
, viewDocuments , viewDocuments
, viewDocuments' --, viewDocuments'
, runCountDocuments , runCountDocuments
, filterWith , filterWith
, runTestAgg , runTestAgg
...@@ -182,15 +182,22 @@ viewDocuments' :: CorpusId ...@@ -182,15 +182,22 @@ viewDocuments' :: CorpusId
-> Maybe Text -> Maybe Text
-> Maybe Text -> Maybe Text
-> Select FacetDocAgg -> Select FacetDocAgg
viewDocuments' cId t ntId mQuery mYear = viewDocuments' cId t ntId mQuery mYear = proc () -> do
aggregate (pFacetDoc FacetDoc { facetDoc_id = OAgg.groupBy fd <- viewDocumentsAgg cId t ntId mQuery mYear -< ()
, facetDoc_created = OAgg.groupBy agg <- (laterally . OAgg.aggregate) sumInt4
, facetDoc_title = OAgg.groupBy (proc fd' -> do
, facetDoc_hyperdata = OAgg.groupBy returnA -< facetDoc_ngramCount fd') -< fd
, facetDoc_category = OAgg.groupBy
, facetDoc_ngramCount = OAgg.sumInt4 returnA -< fd { facetDoc_ngramCount = agg }
, facetDoc_score = OAgg.sum })
(viewDocumentsAgg cId t ntId mQuery mYear) -- aggregate (pFacetDoc FacetDoc { facetDoc_id = OAgg.groupBy
-- , facetDoc_created = OAgg.groupBy
-- , facetDoc_title = OAgg.groupBy
-- , facetDoc_hyperdata = OAgg.groupBy
-- , facetDoc_category = OAgg.groupBy
-- , facetDoc_ngramCount = OAgg.sumInt4
-- , facetDoc_score = OAgg.sum })
-- (viewDocumentsAgg cId t ntId mQuery mYear)
viewDocumentsAgg :: CorpusId viewDocumentsAgg :: CorpusId
-> IsTrash -> IsTrash
...@@ -200,33 +207,32 @@ viewDocumentsAgg :: CorpusId ...@@ -200,33 +207,32 @@ viewDocumentsAgg :: CorpusId
-> Select FacetDocAggPart -> Select FacetDocAggPart
viewDocumentsAgg cId t ntId mQuery mYear = proc () -> do viewDocumentsAgg cId t ntId mQuery mYear = proc () -> do
(c, nc) <- viewDocumentsQuery cId t ntId mQuery mYear -< () (c, nc) <- viewDocumentsQuery cId t ntId mQuery mYear -< ()
agg <- OAgg.aggregate sumInt4 (aggQ (nc ^. nc_node_id) (c ^. cs_id)) -< () -- agg <- OAgg.aggregate sumInt4 (aggQ (nc ^. nc_node_id) (c ^. cs_id)) -< ()
-- agg <- OAgg.aggregate sumInt4 -- agg <- (laterally . OAgg.aggregate) sumInt4
-- (proc (c', nc') -> do -- (proc (c', nc') -> do
-- cnng <- queryContextNodeNgramsTable -< () -- cnng <- queryContextNodeNgramsTable -< ()
-- restrict -< (cnng ^. cnng_node_id) .== (nc' ^. nc_node_id) -- restrict -< (cnng ^. cnng_node_id) .== (nc' ^. nc_node_id)
-- restrict -< (cnng ^. cnng_context_id) .== (c' ^. cs_id) -- restrict -< (cnng ^. cnng_context_id) .== (c' ^. cs_id)
-- returnA -< (cnng ^. cnng_doc_count)) -< (c, nc) -- returnA -< (cnng ^. cnng_doc_count)) -< (c, nc)
-- cnng <- optionalRestrict queryContextNodeNgramsTable -< cnng <- optionalRestrict queryContextNodeNgramsTable -<
-- \cnng' -> (cnng' ^. cnng_node_id) .== (nc ^. nc_node_id) .&& \cnng' -> (cnng' ^. cnng_node_id) .== (nc ^. nc_node_id) .&&
-- (cnng' ^. cnng_context_id) .== (c ^. cs_id) (cnng' ^. cnng_context_id) .== (c ^. cs_id)
returnA -< FacetDoc { facetDoc_id = _cs_id c returnA -< FacetDoc { facetDoc_id = _cs_id c
, facetDoc_created = _cs_date c , facetDoc_created = _cs_date c
, facetDoc_title = _cs_name c , facetDoc_title = _cs_name c
, facetDoc_hyperdata = _cs_hyperdata c , facetDoc_hyperdata = _cs_hyperdata c
, facetDoc_category = nc ^. nc_category , facetDoc_category = nc ^. nc_category
, facetDoc_ngramCount = fromIntegral agg -- , facetDoc_ngramCount = agg
-- , facetDoc_ngramCount = fromMaybeFields 0 $ _cnng_doc_count <$> cnng -- toNullable $ nc^. , facetDoc_ngramCount = fromMaybeFields 0 $ _cnng_doc_count <$> cnng -- toNullable $ nc^. nc_score
nc_score
-- , facetDoc_ngramCount = toNullable $ toFields cnt -- , facetDoc_ngramCount = toNullable $ toFields cnt
, facetDoc_score = nc ^. nc_score , facetDoc_score = nc ^. nc_score
} }
aggQ ncId cId = proc () -> do -- aggQ ncId cId = proc () -> do
cnng <- queryContextNodeNgramsTable -< () -- cnng <- queryContextNodeNgramsTable -< ()
restrict -< (cnng ^. cnng_node_id) .== ncId -- restrict -< (cnng ^. cnng_node_id) .== ncId
restrict -< (cnng ^. cnng_context_id) .== cId -- restrict -< (cnng ^. cnng_context_id) .== cId
returnA -< (cnng ^. cnng_doc_count) -- returnA -< (cnng ^. cnng_doc_count)
-- TODO Join with context_node_ngrams at context_id/node_id and sum by -- TODO Join with context_node_ngrams at context_id/node_id and sum by
-- doc_count. -- doc_count.
......
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