Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
haskell-gargantext
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Julien Moutinho
haskell-gargantext
Commits
3f2be39d
Commit
3f2be39d
authored
Dec 08, 2018
by
Alexandre Delanoë
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[SQL][JOINS] leftJoin4.
parent
8db4a063
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
101 additions
and
39 deletions
+101
-39
Facet.hs
src/Gargantext/Database/Facet.hs
+41
-31
TextSearch.hs
src/Gargantext/Database/TextSearch.hs
+59
-7
Utils.hs
src/Gargantext/Database/Utils.hs
+1
-1
No files found.
src/Gargantext/Database/Facet.hs
View file @
3f2be39d
...
...
@@ -236,9 +236,6 @@ filterDocuments o l order q = limit' l $ offset' o $ orderBy ordering q
(
Just
FavDesc
)
->
desc
facetDoc_favorite
_
->
desc
facetDoc_created
------------------------------------------------------------------------
-- | TODO move this queries utilties elsewhere
...
...
@@ -267,45 +264,58 @@ leftJoin3 :: ( Default Unpackspec columnsL1 columnsL1
leftJoin3
q1
q2
q3
cond12
cond23
=
leftJoin
q3
(
leftJoin
q1
q2
cond12
)
cond23
--{-
leftJoin4'
::
Query
(
NodeRead
,
(
NodeReadNull
,
(
NgramsReadNull
,
NodeReadNull
)))
leftJoin4'
=
leftJoin4
queryNgramsTable
queryNodeTable
queryNodeTable
queryNodeTable
cond12
cond23
cond34
where
cond12
::
(
NgramsRead
,
NodeRead
)
->
Column
PGBool
cond12
=
undefined
cond23
::
(
NodeRead
,
(
NgramsRead
,
NodeReadNull
))
->
Column
PGBool
cond23
=
undefined
cond34
::
(
NodeRead
,
(
NodeRead
,
(
NgramsReadNull
,
NodeReadNull
)))
->
Column
PGBool
cond34
=
undefined
leftJoin4'
::
Query
(
NodeRead
,
(
NodeReadNull
,
(
NodeReadNull
,
NodeReadNull
)))
leftJoin4'
=
leftJoin4
queryNodeTable
queryNodeTable
queryNodeTable
queryNodeTable
cond12
cond23
cond34
{-
rightJoin4' :: Query (((NodeReadNull, NodeReadNull), NodeReadNull), NodeRead)
rightJoin4' = rightJoin4 queryNodeTable queryNodeTable queryNodeTable queryNodeTable cond12 cond23 cond34
where
cond12 :: (NodeRead, NodeRead) -> Column PGBool
cond12 = undefined
cond23
::
(
NodeRead
,
(
NodeRead
,
NodeReadNull
)
)
->
Column
PGBool
cond23 :: (
(NodeReadNull, NodeRead), NodeRead
) -> Column PGBool
cond23 = undefined
cond34
::
(
NodeRead
,
(
NodeRead
,
(
NodeReadNull
,
NodeReadNull
))
)
->
Column
PGBool
cond34 :: (
((NodeReadNull, NodeReadNull), NodeRead), NodeRead
) -> Column PGBool
cond34 = undefined
--}
leftJoin4
::
(
Default
Unpackspec
fieldsL1
fieldsL1
,
Default
Unpackspec
fieldsL2
fieldsL2
,
Default
Unpackspec
fieldsL3
fieldsL3
,
Default
Unpackspec
fieldsR
fieldsR
,
Default
Unpackspec
nullableFieldsL1
nullableFieldsL1
,
Default
Unpackspec
nullableFieldsL2
nullableFieldsL2
,
Default
NullMaker
fieldsR
nullableFieldsL2
,
Default
NullMaker
(
fieldsL2
,
nullableFieldsL1
)
nullableFieldsL3
,
Default
NullMaker
(
fieldsL3
,
nullableFieldsL2
)
nullableFieldsL1
)
=>
Query
fieldsL3
->
Query
fieldsR
->
Query
fieldsL2
->
Query
fieldsL1
->
((
fieldsL3
,
fieldsR
)
->
Column
PGBool
)
->
((
fieldsL2
,
(
fieldsL3
,
nullableFieldsL2
))
->
Column
PGBool
)
->
((
fieldsL1
,
(
fieldsL2
,
nullableFieldsL1
))
->
Column
PGBool
)
->
Query
(
fieldsL1
,
nullableFieldsL3
)
leftJoin4
::
(
Default
Unpackspec
fieldsL1
fieldsL1
,
Default
Unpackspec
fieldsL2
fieldsL2
,
Default
Unpackspec
nullableFieldsR1
nullableFieldsR1
,
Default
Unpackspec
fieldsL3
fieldsL3
,
Default
Unpackspec
nullableFieldsR2
nullableFieldsR2
,
Default
Unpackspec
fieldsR
fieldsR
,
Default
NullMaker
fieldsR
nullableFieldsR2
,
Default
NullMaker
(
fieldsL2
,
nullableFieldsR1
)
nullableFieldsR3
,
Default
NullMaker
(
fieldsL3
,
nullableFieldsR2
)
nullableFieldsR1
)
=>
Opaleye
.
Select
fieldsL3
->
Opaleye
.
Select
fieldsR
->
Opaleye
.
Select
fieldsL2
->
Opaleye
.
Select
fieldsL1
->
((
fieldsL3
,
fieldsR
)
->
Column
PGBool
)
->
((
fieldsL2
,
(
fieldsL3
,
nullableFieldsR2
))
->
Column
PGBool
)
->
((
fieldsL1
,
(
fieldsL2
,
nullableFieldsR1
))
->
Column
PGBool
)
->
Opaleye
.
Select
(
fieldsL1
,
nullableFieldsR3
)
leftJoin4
q1
q2
q3
q4
cond12
cond23
cond34
=
leftJoin
q4
(
leftJoin
q3
(
leftJoin
q1
q2
cond12
)
cond23
)
cond34
--}
{-
-}
-- rightJoin4 q1 q2 q3 q4 cond12 cond23 cond34 = rightJoin q4 (rightJoin q3 (rightJoin q1 q2 cond12) cond23) cond34
leftJoin5'
::
Query
(
NodeRead
,
(
NodeReadNull
,
(
NodeReadNull
,
(
NodeReadNull
,
NodeReadNull
))))
leftJoin5'
=
leftJoin5
queryNodeTable
queryNodeTable
queryNodeTable
queryNodeTable
queryNodeTable
cond12
cond23
cond34
cond45
where
...
...
src/Gargantext/Database/TextSearch.hs
View file @
3f2be39d
...
...
@@ -20,14 +20,17 @@ module Gargantext.Database.TextSearch where
import
Data.Aeson
import
Data.List
(
intersperse
)
import
Data.String
(
IsString
(
..
))
import
Data.Text
(
Text
,
words
)
import
Data.Text
(
Text
,
words
,
unpack
)
import
Database.PostgreSQL.Simple
import
Database.PostgreSQL.Simple.ToField
import
Gargantext.Database.Config
(
nodeTypeId
)
import
Gargantext.Database.Types.Node
(
NodeType
(
..
))
import
Gargantext.Prelude
import
Gargantext.Database.Facet
import
Gargantext.Database.Node
import
Gargantext.Database.Ngrams
import
Gargantext.Database.NodeNode
import
Gargantext.Database.NodeNgram
import
Gargantext.Database.Queries
import
Gargantext.Core.Types
import
Control.Arrow
(
returnA
)
...
...
@@ -36,13 +39,62 @@ import Opaleye hiding (Query, Order)
newtype
TSQuery
=
UnsafeTSQuery
[
Text
]
globalTextSearch
::
Connection
->
ParentId
->
Text
->
IO
[(
NodeId
,
HyperdataDocument
)]
globalTextSearch
c
p
t
=
runQuery
c
(
globalTextSearchQuery
p
t
)
searchQuery
::
O
.
Query
NodeRead
searchQuery
=
proc
()
->
do
-- | Global search query where ParentId is Master Node Corpus Id
globalTextSearchQuery
::
ParentId
->
Text
->
O
.
Query
(
Column
PGInt4
,
Column
PGJsonb
)
globalTextSearchQuery
_
q
=
proc
()
->
do
row
<-
queryNodeTable
-<
()
restrict
-<
(
_node_search
row
)
@@
(
pgTSQuery
"test"
)
returnA
-<
row
restrict
-<
(
_node_search
row
)
@@
(
pgTSQuery
(
unpack
q
))
restrict
-<
(
_node_typename
row
)
.==
(
pgInt4
$
nodeTypeId
NodeDocument
)
returnA
-<
(
_node_id
row
,
_node_hyperdata
row
)
------------------------------------------------------------------------
{-
graphCorpusAuthorQuery :: O.Query (NodeRead, (NodeNgramRead, (NgramsReadNull, NodeNgramReadNull)))
graphCorpusAuthorQuery = leftJoin4 queryNgramsTable queryNodeNgramTable queryNodeNgramTable queryNodeTable cond12 cond23 cond34
where
--cond12 :: (NgramsRead, NodeNgramRead) -> Column PGBool
cond12 = undefined
cond23 :: (NodeNgramRead, (NodeNgramRead, NodeNgramReadNull)) -> Column PGBool
cond23 = undefined
cond34 :: (NodeRead, (NodeNgramRead, (NodeReadNull, NodeNgramReadNull))) -> Column PGBool
cond34 = undefined
--}
--runGraphCorpusDocSearch :: Connection -> CorpusId -> Text -> IO [(Column PGInt4, Column PGJsonb)]
--runGraphCorpusDocSearch c cId t = runQuery c $ graphCorpusDocSearch cId t
-- | todo add limit and offset and order
graphCorpusDocSearch
::
CorpusId
->
Text
->
O
.
Query
(
Column
PGInt4
,
Column
PGJsonb
)
graphCorpusDocSearch
cId
t
=
proc
()
->
do
(
n
,
nn
)
<-
graphCorpusDocSearchQuery
-<
()
restrict
-<
(
_node_search
n
)
@@
(
pgTSQuery
(
unpack
t
))
restrict
-<
(
nodeNode_node1_id
nn
)
.==
(
toNullable
$
pgInt4
cId
)
restrict
-<
(
_node_typename
n
)
.==
(
pgInt4
$
nodeTypeId
NodeDocument
)
returnA
-<
(
_node_id
n
,
_node_hyperdata
n
)
graphCorpusDocSearchQuery
::
O
.
Query
(
NodeRead
,
NodeNodeReadNull
)
graphCorpusDocSearchQuery
=
leftJoin
queryNodeTable
queryNodeNodeTable
cond
where
cond
::
(
NodeRead
,
NodeNodeRead
)
->
Column
PGBool
cond
(
n
,
nn
)
=
nodeNode_node1_id
nn
.==
_node_id
n
...
...
src/Gargantext/Database/Utils.hs
View file @
3f2be39d
...
...
@@ -80,4 +80,4 @@ fromField' field mb = do
Error
_err
->
returnError
ConversionFailed
field
"cannot parse hyperdata"
-- | Opaleye leftJoin* functions
-- TODO add here from Node.hs
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment