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
Christian Merten
haskell-gargantext
Commits
9a203130
Commit
9a203130
authored
Jun 19, 2024
by
Karen Konou
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[Contexts for ngrams] Support AND search
parent
e147c115
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
37 additions
and
9 deletions
+37
-9
Context.hs
src/Gargantext/API/GraphQL/Context.hs
+6
-5
NodeContext.hs
src/Gargantext/Database/Query/Table/NodeContext.hs
+31
-4
No files found.
src/Gargantext/API/GraphQL/Context.hs
View file @
9a203130
...
@@ -94,6 +94,7 @@ data ContextsForNgramsArgs
...
@@ -94,6 +94,7 @@ data ContextsForNgramsArgs
=
ContextsForNgramsArgs
=
ContextsForNgramsArgs
{
corpus_id
::
Int
{
corpus_id
::
Int
,
ngrams_terms
::
[
Text
]
,
ngrams_terms
::
[
Text
]
,
and_logic
::
Bool
}
deriving
(
Generic
,
GQLType
)
}
deriving
(
Generic
,
GQLType
)
data
NodeContextCategoryMArgs
=
NodeContextCategoryMArgs
data
NodeContextCategoryMArgs
=
NodeContextCategoryMArgs
...
@@ -123,8 +124,8 @@ resolveNodeContext NodeContextArgs { context_id, node_id } =
...
@@ -123,8 +124,8 @@ resolveNodeContext NodeContextArgs { context_id, node_id } =
resolveContextsForNgrams
resolveContextsForNgrams
::
(
CmdCommon
env
)
::
(
CmdCommon
env
)
=>
ContextsForNgramsArgs
->
GqlM
e
env
[
ContextGQL
]
=>
ContextsForNgramsArgs
->
GqlM
e
env
[
ContextGQL
]
resolveContextsForNgrams
ContextsForNgramsArgs
{
corpus_id
,
ngrams_terms
}
=
resolveContextsForNgrams
ContextsForNgramsArgs
{
corpus_id
,
ngrams_terms
,
and_logic
}
=
dbContextForNgrams
corpus_id
ngrams_terms
dbContextForNgrams
corpus_id
ngrams_terms
and_logic
resolveContextNgrams
resolveContextNgrams
::
(
CmdCommon
env
)
::
(
CmdCommon
env
)
...
@@ -149,9 +150,9 @@ dbNodeContext context_id node_id = do
...
@@ -149,9 +150,9 @@ dbNodeContext context_id node_id = do
-- | Returns list of `ContextGQL` for given ngrams in given corpus id.
-- | Returns list of `ContextGQL` for given ngrams in given corpus id.
dbContextForNgrams
dbContextForNgrams
::
(
CmdCommon
env
)
::
(
CmdCommon
env
)
=>
Int
->
[
Text
]
->
GqlM
e
env
[
ContextGQL
]
=>
Int
->
[
Text
]
->
Bool
->
GqlM
e
env
[
ContextGQL
]
dbContextForNgrams
node_id
ngrams_terms
=
do
dbContextForNgrams
node_id
ngrams_terms
and_logic
=
do
contextsForNgramsTerms
<-
lift
$
getContextsForNgramsTerms
(
UnsafeMkNodeId
node_id
)
ngrams_terms
contextsForNgramsTerms
<-
lift
$
getContextsForNgramsTerms
(
UnsafeMkNodeId
node_id
)
ngrams_terms
and_logic
--lift $ printDebug "[dbContextForNgrams] contextsForNgramsTerms" contextsForNgramsTerms
--lift $ printDebug "[dbContextForNgrams] contextsForNgramsTerms" contextsForNgramsTerms
pure
$
toContextGQL
<$>
contextsForNgramsTerms
pure
$
toContextGQL
<$>
contextsForNgramsTerms
...
...
src/Gargantext/Database/Query/Table/NodeContext.hs
View file @
9a203130
...
@@ -152,9 +152,11 @@ data ContextForNgramsTerms =
...
@@ -152,9 +152,11 @@ data ContextForNgramsTerms =
getContextsForNgramsTerms
::
HasNodeError
err
getContextsForNgramsTerms
::
HasNodeError
err
=>
NodeId
=>
NodeId
->
[
Text
]
->
[
Text
]
->
Bool
->
DBCmd
err
[
ContextForNgramsTerms
]
->
DBCmd
err
[
ContextForNgramsTerms
]
getContextsForNgramsTerms
cId
ngramsTerms
=
do
getContextsForNgramsTerms
cId
ngramsTerms
and_logic
=
do
res
<-
runPGSQuery
query
(
cId
,
PGS
.
In
ngramsTerms
)
let
terms_length
=
length
ngramsTerms
res
<-
runPGSQuery
(
query
and_logic
)
(
cId
,
PGS
.
In
ngramsTerms
,
terms_length
)
pure
$
(
\
(
_cfnt_nodeId
pure
$
(
\
(
_cfnt_nodeId
,
_cfnt_hash
,
_cfnt_hash
,
_cfnt_nodeTypeId
,
_cfnt_nodeTypeId
...
@@ -166,8 +168,8 @@ getContextsForNgramsTerms cId ngramsTerms = do
...
@@ -166,8 +168,8 @@ getContextsForNgramsTerms cId ngramsTerms = do
,
_cfnt_score
,
_cfnt_score
,
_cfnt_category
)
->
ContextForNgramsTerms
{
..
})
<$>
res
,
_cfnt_category
)
->
ContextForNgramsTerms
{
..
})
<$>
res
where
where
query
::
PGS
.
Query
query
::
Bool
->
PGS
.
Query
query
=
[
sql
|
SELECT t.id, t.hash_id, t.typename, t.user_id, t.parent_id, t.name, t.date, t.hyperdata, t.score, t.category
query
False
=
[
sql
|
SELECT t.id, t.hash_id, t.typename, t.user_id, t.parent_id, t.name, t.date, t.hyperdata, t.score, t.category
FROM (
FROM (
SELECT DISTINCT ON (contexts.id)
SELECT DISTINCT ON (contexts.id)
contexts.id AS id,
contexts.id AS id,
...
@@ -190,6 +192,31 @@ getContextsForNgramsTerms cId ngramsTerms = do
...
@@ -190,6 +192,31 @@ getContextsForNgramsTerms cId ngramsTerms = do
-- ORDER BY t.doc_count DESC
-- ORDER BY t.doc_count DESC
ORDER BY t.score DESC
ORDER BY t.score DESC
|]
|]
query
True
=
[
sql
|
SELECT t.id, t.hash_id, t.typename, t.user_id, t.parent_id, t.name, t.date, t.hyperdata, t.score, t.category
FROM (
SELECT DISTINCT ON (contexts.id)
contexts.id AS id,
hash_id,
typename,
user_id,
parent_id,
name,
date,
hyperdata,
nodes_contexts.score AS score,
nodes_contexts.category AS category --,
-- context_node_ngrams.doc_count AS doc_count
FROM contexts
JOIN context_node_ngrams ON contexts.id = context_node_ngrams.context_id
JOIN nodes_contexts ON contexts.id = nodes_contexts.context_id
JOIN ngrams ON context_node_ngrams.ngrams_id = ngrams.id
WHERE nodes_contexts.node_id = ?
AND ngrams.terms IN ?
GROUP BY contexts.id
HAVING COUNT(DISTINCT ngrams.terms) = ?) t
-- ORDER BY t.doc_count DESC
ORDER BY t.score DESC
|]
...
...
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