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

[FIX] Graph Search with selected node (context migration related)

parent 8d7076d5
......@@ -25,8 +25,11 @@ import Gargantext.Database.Query.Facet
import Gargantext.Database.Query.Filter
import Gargantext.Database.Query.Join (leftJoin5)
import Gargantext.Database.Query.Table.Node
import Gargantext.Database.Query.Table.Context
import Gargantext.Database.Query.Table.NodeNode
import Gargantext.Database.Query.Table.NodeContext
import Gargantext.Database.Schema.Node
import Gargantext.Database.Schema.Context
import Gargantext.Prelude
import Gargantext.Core.Text.Terms.Mono.Stem.En (stemIt)
import Opaleye hiding (Order)
......@@ -80,27 +83,27 @@ queryInCorpus :: HasDBid NodeType
-> Text
-> O.Select FacetDocRead
queryInCorpus cId t q = proc () -> do
(n, nn) <- joinInCorpus -< ()
restrict -< (nn^.nn_node1_id) .== (toNullable $ pgNodeId cId)
(c, nc) <- joinInCorpus -< ()
restrict -< (nc^.nc_node_id) .== (toNullable $ pgNodeId cId)
restrict -< if t
then (nn^.nn_category) .== (toNullable $ sqlInt4 0)
else (nn^.nn_category) .>= (toNullable $ sqlInt4 1)
restrict -< (n ^. ns_search) @@ (sqlTSQuery (unpack q))
restrict -< (n ^. ns_typename ) .== (sqlInt4 $ toDBid NodeDocument)
returnA -< FacetDoc { facetDoc_id = n^.ns_id
, facetDoc_created = n^.ns_date
, facetDoc_title = n^.ns_name
, facetDoc_hyperdata = n^.ns_hyperdata
, facetDoc_category = nn^.nn_category
, facetDoc_ngramCount = nn^.nn_score
, facetDoc_score = nn^.nn_score
then (nc^.nc_category) .== (toNullable $ sqlInt4 0)
else (nc^.nc_category) .>= (toNullable $ sqlInt4 1)
restrict -< (c ^. cs_search) @@ (sqlTSQuery (unpack q))
restrict -< (c ^. cs_typename ) .== (sqlInt4 $ toDBid NodeDocument)
returnA -< FacetDoc { facetDoc_id = c^.cs_id
, facetDoc_created = c^.cs_date
, facetDoc_title = c^.cs_name
, facetDoc_hyperdata = c^.cs_hyperdata
, facetDoc_category = nc^.nc_category
, facetDoc_ngramCount = nc^.nc_score
, facetDoc_score = nc^.nc_score
}
joinInCorpus :: O.Select (NodeSearchRead, NodeNodeReadNull)
joinInCorpus = leftJoin queryNodeSearchTable queryNodeNodeTable cond
joinInCorpus :: O.Select (ContextSearchRead, NodeContextReadNull)
joinInCorpus = leftJoin queryContextSearchTable queryNodeContextTable cond
where
cond :: (NodeSearchRead, NodeNodeRead) -> Column SqlBool
cond (n, nn) = nn^.nn_node2_id .== _ns_id n
cond :: (ContextSearchRead, NodeContextRead) -> Column SqlBool
cond (c, nc) = nc^.nc_context_id .== _cs_id c
------------------------------------------------------------------------
searchInCorpusWithContacts
......
......@@ -20,7 +20,7 @@ Portability : POSIX
module Gargantext.Database.Query.Facet
( runViewAuthorsDoc
, runViewDocuments
, viewDocuments'
-- , viewDocuments'
, runCountDocuments
, filterWith
......@@ -306,8 +306,7 @@ runViewDocuments cId t o l order query = do
printDebug "[runViewDocuments] sqlQuery" $ showSql sqlQuery
runOpaQuery $ filterWith o l order sqlQuery
where
ntId = toDBid NodeDocument
sqlQuery = viewDocuments cId t ntId query
sqlQuery = viewDocuments cId t (toDBid NodeDocument) query
runCountDocuments :: HasDBid NodeType => CorpusId -> IsTrash -> Maybe Text -> Cmd err Int
runCountDocuments cId t mQuery = do
......@@ -331,22 +330,6 @@ viewDocuments cId t ntId mQuery = viewDocumentsQuery cId t ntId mQuery >>> proc
, facetDoc_score = toNullable $ nc^.nc_score
}
viewDocuments' :: CorpusId
-> IsTrash
-> NodeTypeId
-> Maybe Text
-> Select NodeRead
viewDocuments' cId t ntId mQuery = viewDocumentsQuery cId t ntId mQuery >>> proc (c, _nc) -> do
returnA -< Node { _node_id = _cs_id c
, _node_hash_id = ""
, _node_typename = _cs_typename c
, _node_user_id = _cs_user_id c
, _node_parent_id = -1
, _node_name = _cs_name c
, _node_date = _cs_date c
, _node_hyperdata = _cs_hyperdata c
}
viewDocumentsQuery :: CorpusId
-> IsTrash
-> NodeTypeId
......
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