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
d187e0b3
Commit
d187e0b3
authored
Jul 05, 2024
by
Alexandre Delanoë
Browse files
Options
Browse Files
Download
Plain Diff
Merge remote-tracking branch 'origin/242-dev-phylo-websearch' into dev
parents
b843188e
7a46e772
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
54 additions
and
7 deletions
+54
-7
Context.hs
src/Gargantext/API/GraphQL/Context.hs
+8
-6
NodeContext.hs
src/Gargantext/Database/Query/Table/NodeContext.hs
+46
-1
No files found.
src/Gargantext/API/GraphQL/Context.hs
View file @
d187e0b3
...
...
@@ -22,7 +22,8 @@ import Data.Morpheus.Types
,
ResolverM
,
QUERY
)
import
Data.Text
(
pack
)
import
Data.Text
(
pack
,
unpack
)
import
qualified
Data.Text
as
Text
import
Data.Time.Format.ISO8601
(
iso8601Show
)
import
Gargantext.API.Admin.Types
(
HasSettings
)
import
Gargantext.API.Errors.Types
(
BackendInternalError
)
...
...
@@ -94,6 +95,7 @@ data ContextsForNgramsArgs
=
ContextsForNgramsArgs
{
corpus_id
::
Int
,
ngrams_terms
::
[
Text
]
,
and_logic
::
Text
}
deriving
(
Generic
,
GQLType
)
data
NodeContextCategoryMArgs
=
NodeContextCategoryMArgs
...
...
@@ -123,8 +125,8 @@ resolveNodeContext NodeContextArgs { context_id, node_id } =
resolveContextsForNgrams
::
(
CmdCommon
env
)
=>
ContextsForNgramsArgs
->
GqlM
e
env
[
ContextGQL
]
resolveContextsForNgrams
ContextsForNgramsArgs
{
corpus_id
,
ngrams_terms
}
=
dbContextForNgrams
corpus_id
ngrams_terms
resolveContextsForNgrams
ContextsForNgramsArgs
{
corpus_id
,
ngrams_terms
,
and_logic
}
=
dbContextForNgrams
corpus_id
ngrams_terms
and_logic
resolveContextNgrams
::
(
CmdCommon
env
)
...
...
@@ -149,9 +151,9 @@ dbNodeContext context_id node_id = do
-- | Returns list of `ContextGQL` for given ngrams in given corpus id.
dbContextForNgrams
::
(
CmdCommon
env
)
=>
Int
->
[
Text
]
->
GqlM
e
env
[
ContextGQL
]
dbContextForNgrams
node_id
ngrams_terms
=
do
contextsForNgramsTerms
<-
lift
$
getContextsForNgramsTerms
(
UnsafeMkNodeId
node_id
)
ngrams_terms
=>
Int
->
[
Text
]
->
Text
->
GqlM
e
env
[
ContextGQL
]
dbContextForNgrams
node_id
ngrams_terms
and_logic
=
do
contextsForNgramsTerms
<-
lift
$
getContextsForNgramsTerms
(
UnsafeMkNodeId
node_id
)
ngrams_terms
(
readMaybe
$
unpack
$
Text
.
toTitle
and_logic
)
--lift $ printDebug "[dbContextForNgrams] contextsForNgramsTerms" contextsForNgramsTerms
pure
$
toContextGQL
<$>
contextsForNgramsTerms
...
...
src/Gargantext/Database/Query/Table/NodeContext.hs
View file @
d187e0b3
...
...
@@ -152,8 +152,53 @@ data ContextForNgramsTerms =
getContextsForNgramsTerms
::
HasNodeError
err
=>
NodeId
->
[
Text
]
->
Maybe
Bool
->
DBCmd
err
[
ContextForNgramsTerms
]
getContextsForNgramsTerms
cId
ngramsTerms
=
do
getContextsForNgramsTerms
cId
ngramsTerms
(
Just
True
)
=
do
let
terms_length
=
length
ngramsTerms
res
<-
runPGSQuery
query
(
cId
,
PGS
.
In
ngramsTerms
,
terms_length
)
pure
$
(
\
(
_cfnt_nodeId
,
_cfnt_hash
,
_cfnt_nodeTypeId
,
_cfnt_userId
,
_cfnt_parentId
,
_cfnt_c_title
,
_cfnt_date
,
_cfnt_hyperdata
,
_cfnt_score
,
_cfnt_category
)
->
ContextForNgramsTerms
{
..
})
<$>
res
where
query
::
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
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,
nodes_contexts.score,
nodes_contexts.category
HAVING COUNT(DISTINCT ngrams.terms) = ?) t
-- ORDER BY t.doc_count DESC
ORDER BY t.score DESC
|]
getContextsForNgramsTerms
cId
ngramsTerms
_
=
do
res
<-
runPGSQuery
query
(
cId
,
PGS
.
In
ngramsTerms
)
pure
$
(
\
(
_cfnt_nodeId
,
_cfnt_hash
...
...
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