Commit b3ad95a1 authored by Alexandre Delanoë's avatar Alexandre Delanoë

[Search] Contacts via doc : ok :)

parent 88489429
...@@ -36,6 +36,7 @@ import Gargantext.Database.Schema.Node ...@@ -36,6 +36,7 @@ import Gargantext.Database.Schema.Node
import Gargantext.Prelude import Gargantext.Prelude
import Gargantext.Text.Terms.Mono.Stem.En (stemIt) import Gargantext.Text.Terms.Mono.Stem.En (stemIt)
import Opaleye hiding (Query, Order) import Opaleye hiding (Query, Order)
import Data.Profunctor.Product (p4)
import qualified Opaleye as O hiding (Order) import qualified Opaleye as O hiding (Order)
------------------------------------------------------------------------ ------------------------------------------------------------------------
...@@ -113,17 +114,17 @@ searchInCorpusWithContacts ...@@ -113,17 +114,17 @@ searchInCorpusWithContacts
searchInCorpusWithContacts cId aId q o l _order = searchInCorpusWithContacts cId aId q o l _order =
runOpaQuery $ limit' l runOpaQuery $ limit' l
$ offset' o $ offset' o
-- $ orderBy ( o l order $ orderBy ( desc _fp_score)
$ selectContactViaDoc cId aId $ group cId aId
$ intercalate " | " $ intercalate " | "
$ map stemIt q $ map stemIt q
-- TODO group by
selectContactViaDoc selectContactViaDoc
:: CorpusId :: CorpusId
-> AnnuaireId -> AnnuaireId
-> Text -> Text
-> O.Query FacetPairedReadNull -> Select FacetPairedReadNull
selectContactViaDoc cId aId q = proc () -> do selectContactViaDoc cId aId q = proc () -> do
(doc, (corpus_doc, (_contact_doc, (annuaire_contact, contact)))) <- queryContactViaDoc -< () (doc, (corpus_doc, (_contact_doc, (annuaire_contact, contact)))) <- queryContactViaDoc -< ()
restrict -< (doc^.ns_search) @@ (pgTSQuery $ unpack q ) restrict -< (doc^.ns_search) @@ (pgTSQuery $ unpack q )
...@@ -134,7 +135,47 @@ selectContactViaDoc cId aId q = proc () -> do ...@@ -134,7 +135,47 @@ selectContactViaDoc cId aId q = proc () -> do
returnA -< FacetPaired (contact^.node_id) returnA -< FacetPaired (contact^.node_id)
(contact^.node_date) (contact^.node_date)
(contact^.node_hyperdata) (contact^.node_hyperdata)
(toNullable $ pgInt4 0) (toNullable $ pgInt4 1)
selectContactViaDoc'
:: CorpusId
-> AnnuaireId
-> Text
-> QueryArr ()
( Column (Nullable PGInt4)
, Column (Nullable PGTimestamptz)
, Column (Nullable PGJsonb)
, Column (Nullable PGInt4)
)
selectContactViaDoc' cId aId q = proc () -> do
(doc, (corpus_doc, (_contact_doc, (annuaire_contact, contact)))) <- queryContactViaDoc -< ()
restrict -< (doc^.ns_search) @@ (pgTSQuery $ unpack q )
restrict -< (doc^.ns_typename) .== (pgInt4 $ nodeTypeId NodeDocument)
restrict -< (corpus_doc^.nn_node1_id) .== (toNullable $ pgNodeId cId)
restrict -< (annuaire_contact^.nn_node1_id) .== (toNullable $ pgNodeId aId)
restrict -< (contact^.node_typename) .== (toNullable $ pgInt4 $ nodeTypeId NodeContact)
returnA -< ( contact^.node_id
, contact^.node_date
, contact^.node_hyperdata
, toNullable $ pgInt4 1
)
group :: NodeId
-> NodeId
-> Text
-> Select FacetPairedReadNull
group cId aId q = proc () -> do
(a, b, c, d) <- aggregate (p4 (groupBy, groupBy, groupBy, O.sum))
(selectContactViaDoc' cId aId q) -< ()
returnA -< FacetPaired a b c d
queryContactViaDoc :: O.Query ( NodeSearchRead queryContactViaDoc :: O.Query ( NodeSearchRead
, ( NodeNodeReadNull , ( NodeNodeReadNull
......
...@@ -30,6 +30,7 @@ module Gargantext.Database.Query.Facet ...@@ -30,6 +30,7 @@ module Gargantext.Database.Query.Facet
, FacetPaired(..) , FacetPaired(..)
, FacetPairedRead , FacetPairedRead
, FacetPairedReadNull , FacetPairedReadNull
, FacetPairedReadNullAgg
, OrderBy(..) , OrderBy(..)
) )
where where
...@@ -121,6 +122,8 @@ data FacetPaired id date hyperdata score = ...@@ -121,6 +122,8 @@ data FacetPaired id date hyperdata score =
$(deriveJSON (unPrefix "_fp_") ''FacetPaired) $(deriveJSON (unPrefix "_fp_") ''FacetPaired)
$(makeAdaptorAndInstance "pFacetPaired" ''FacetPaired) $(makeAdaptorAndInstance "pFacetPaired" ''FacetPaired)
instance ( ToSchema id instance ( ToSchema id
, ToSchema date , ToSchema date
, ToSchema hyperdata , ToSchema hyperdata
...@@ -149,6 +152,21 @@ type FacetPairedReadNull = FacetPaired (Column (Nullable PGInt4) ) ...@@ -149,6 +152,21 @@ type FacetPairedReadNull = FacetPaired (Column (Nullable PGInt4) )
(Column (Nullable PGJsonb) ) (Column (Nullable PGJsonb) )
(Column (Nullable PGInt4) ) (Column (Nullable PGInt4) )
type FacetPairedReadNullAgg = FacetPaired (Aggregator (Column (Nullable PGInt4) )
(Column (Nullable PGInt4) )
)
(Aggregator (Column (Nullable PGTimestamptz))
(Column (Nullable PGTimestamptz))
)
(Aggregator (Column (Nullable PGJsonb) )
(Column (Nullable PGJsonb) )
)
(Aggregator (Column (Nullable PGInt4) )
(Column (Nullable PGInt4) )
)
-- | JSON instance -- | JSON instance
......
...@@ -97,7 +97,7 @@ getNodeNodeWith pId _ maybeNodeType = runOpaQuery query ...@@ -97,7 +97,7 @@ getNodeNodeWith pId _ maybeNodeType = runOpaQuery query
------------------------------------------------------------------------ ------------------------------------------------------------------------
insertNodeNode :: [NodeNode] -> Cmd err Int insertNodeNode :: [NodeNode] -> Cmd err Int
insertNodeNode ns = mkCmd $ \conn -> fromIntegral <$> (runInsert_ conn insertNodeNode ns = mkCmd $ \conn -> fromIntegral <$> (runInsert_ conn
$ Insert nodeNodeTable ns' rCount Nothing) $ Insert nodeNodeTable ns' rCount (Just DoNothing))
where where
ns' :: [NodeNodeWrite] ns' :: [NodeNodeWrite]
ns' = map (\(NodeNode n1 n2 x y) ns' = map (\(NodeNode n1 n2 x y)
......
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