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