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
152
Issues
152
List
Board
Labels
Milestones
Merge Requests
9
Merge Requests
9
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
gargantext
haskell-gargantext
Commits
ff93628e
Verified
Commit
ff93628e
authored
Jun 01, 2023
by
Przemyslaw Kaminski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[graphql] use FTS instead of context table match for context ngrams
parent
6645b901
Pipeline
#4111
canceled with stages
Changes
2
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
29 additions
and
2 deletions
+29
-2
Context.hs
src/Gargantext/API/GraphQL/Context.hs
+2
-2
NodeContext.hs
src/Gargantext/Database/Query/Table/NodeContext.hs
+27
-0
No files found.
src/Gargantext/API/GraphQL/Context.hs
View file @
ff93628e
...
...
@@ -20,7 +20,7 @@ import Gargantext.Core.Types.Search (HyperdataRow(..), toHyperdataRow)
import
Gargantext.Database.Admin.Types.Hyperdata
(
HyperdataDocument
)
import
Gargantext.Database.Admin.Types.Node
(
ContextTitle
,
NodeId
(
..
),
NodeTypeId
,
UserId
,
unNodeId
)
import
Gargantext.Database.Prelude
(
CmdCommon
)
import
Gargantext.Database.Query.Table.NodeContext
(
getNodeContext
,
getContextsForNgramsTerms
,
ContextForNgramsTerms
(
..
),
getContextNgrams
)
import
Gargantext.Database.Query.Table.NodeContext
(
getNodeContext
,
getContextsForNgramsTerms
,
ContextForNgramsTerms
(
..
),
{- getContextNgrams, -}
getContextNgramsMatchingFTS
)
import
qualified
Gargantext.Database.Query.Table.NodeContext
as
DNC
import
Gargantext.Database.Schema.NodeContext
(
NodeContext
,
NodeContextPoly
(
..
))
import
Gargantext.Prelude
...
...
@@ -150,7 +150,7 @@ dbContextNgrams
::
(
CmdCommon
env
)
=>
Int
->
Int
->
GqlM
e
env
[
Text
]
dbContextNgrams
context_id
list_id
=
do
lift
$
getContextNgrams
(
NodeId
context_id
)
(
NodeId
list_id
)
lift
$
getContextNgrams
MatchingFTS
(
NodeId
context_id
)
(
NodeId
list_id
)
-- Conversion functions
...
...
src/Gargantext/Database/Query/Table/NodeContext.hs
View file @
ff93628e
...
...
@@ -34,6 +34,7 @@ module Gargantext.Database.Query.Table.NodeContext
,
ContextForNgrams
(
..
)
,
getContextsForNgramsTerms
,
getContextNgrams
,
getContextNgramsMatchingFTS
,
ContextForNgramsTerms
(
..
)
,
insertNodeContext
,
deleteNodeContext
...
...
@@ -191,6 +192,9 @@ getContextsForNgramsTerms cId ngramsTerms = do
-- | Query the `context_node_ngrams` table and return ngrams for given
-- `context_id` and `list_id`.
-- WARNING: `context_node_ngrams` can be outdated.
getContextNgrams
::
HasNodeError
err
=>
NodeId
->
NodeId
...
...
@@ -206,6 +210,29 @@ getContextNgrams contextId listId = do
JOIN ngrams ON ngrams.id = ngrams_id
WHERE context_id = ?
AND node_id = ?
|]
-- | Query the `contexts` table and return ngrams for given context_id
-- and list_id that match the search tsvector.
-- NOTE This is poor man's tokenization that is used as a hint for the
-- frontend highlighter.
getContextNgramsMatchingFTS
::
HasNodeError
err
=>
NodeId
->
NodeId
->
Cmd
err
[
Text
]
getContextNgramsMatchingFTS
contextId
listId
=
do
res
<-
runPGSQuery
query
(
contextId
,
listId
)
pure
$
(
\
(
PGS
.
Only
term
)
->
term
)
<$>
res
where
query
::
PGS
.
Query
query
=
[
sql
|
SELECT ngrams.terms
FROM ngrams
JOIN node_ngrams ON node_ngrams.ngrams_id = ngrams.id
CROSS JOIN contexts
WHERE contexts.id = ?
AND node_ngrams.node_id = ?
AND contexts.search @@ phraseto_tsquery(ngrams.terms)
|]
------------------------------------------------------------------------
insertNodeContext
::
[
NodeContext
]
->
Cmd
err
Int
insertNodeContext
ns
=
mkCmd
$
\
conn
->
fromIntegral
<$>
(
runInsert_
conn
...
...
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