Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
P
purescript-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
Grégoire Locqueville
purescript-gargantext
Commits
6500552a
Verified
Commit
6500552a
authored
Apr 27, 2023
by
Przemyslaw Kaminski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[search] implement per-user api key for pubmed search
parent
823a1866
Changes
5
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
244 additions
and
145 deletions
+244
-145
SearchField.purs
...omponents/Forest/Tree/Node/Action/Search/SearchField.purs
+125
-81
Types.purs
...text/Components/Forest/Tree/Node/Action/Search/Types.purs
+83
-60
GraphQL.purs
src/Gargantext/Components/GraphQL.purs
+4
-3
Endpoints.purs
src/Gargantext/Components/GraphQL/Endpoints.purs
+10
-1
Node.purs
src/Gargantext/Components/GraphQL/Node.purs
+22
-0
No files found.
src/Gargantext/Components/Forest/Tree/Node/Action/Search/SearchField.purs
View file @
6500552a
This diff is collapsed.
Click to expand it.
src/Gargantext/Components/Forest/Tree/Node/Action/Search/Types.purs
View file @
6500552a
...
@@ -8,7 +8,6 @@ import Data.Maybe (Maybe(..), fromMaybe, maybe)
...
@@ -8,7 +8,6 @@ import Data.Maybe (Maybe(..), fromMaybe, maybe)
import Data.Newtype (class Newtype)
import Data.Newtype (class Newtype)
import Data.Set (Set)
import Data.Set (Set)
import Data.Set as Set
import Data.Set as Set
import Data.String as String
import Data.Tuple (Tuple)
import Data.Tuple (Tuple)
import Data.Tuple.Nested ((/\))
import Data.Tuple.Nested ((/\))
import Gargantext.Components.GraphQL.IMT as GQLIMT
import Gargantext.Components.GraphQL.IMT as GQLIMT
...
@@ -23,21 +22,18 @@ import Simple.JSON as JSON
...
@@ -23,21 +22,18 @@ import Simple.JSON as JSON
import URI.Extra.QueryPairs as QP
import URI.Extra.QueryPairs as QP
import URI.Query as Q
import URI.Query as Q
type Search = { databases :: Database
type Search = { databases
:: Database
, datafield :: Maybe DataField
, datafield
:: Maybe DataField
, url :: String
, url
:: String
, lang :: Maybe Lang
, lang
:: Maybe Lang
, node_id :: Maybe Int
, node_id
:: Maybe Int
, term :: String
, term
:: String
, years :: Array String
, years
:: Array String
}
}
isIsTex_Advanced :: Maybe DataField -> Boolean
isIsTex_Advanced :: Maybe DataField -> Boolean
isIsTex_Advanced ( Just
isIsTex_Advanced ( Just
( External
( External ( IsTex_Advanced) )
( Just ( IsTex_Advanced)
)
)
) = true
) = true
isIsTex_Advanced _ = false
isIsTex_Advanced _ = false
...
@@ -51,13 +47,13 @@ class Doc a where
...
@@ -51,13 +47,13 @@ class Doc a where
dataFields :: Array DataField
dataFields :: Array DataField
dataFields = [ {- Gargantext
dataFields = [ {- Gargantext
, -} External
Nothing
, -} External
Empty
, Web
, Web
-- , Files
-- , Files
]
]
data DataField = Gargantext
data DataField = Gargantext
| External
(Maybe Database)
| External
Database
| Web
| Web
| Files
| Files
...
@@ -74,9 +70,9 @@ instance Doc DataField where
...
@@ -74,9 +70,9 @@ instance Doc DataField where
doc Files = "Zip files with formats.."
doc Files = "Zip files with formats.."
derive instance Eq DataField
derive instance Eq DataField
instance JSON.WriteForeign DataField where
instance JSON.WriteForeign DataField where
writeImpl (External
(Just db)) = JSON.writeImpl $ "External " <> show db
writeImpl (External
db) = JSON.writeImpl { tag: "External"
writeImpl Web = JSON.writeImpl $ "Web"
, contents: JSON.writeImpl db }
writeImpl f = JSON.writeImpl $
show f
writeImpl f = JSON.writeImpl $
JSON.writeImpl { tag: show f }
----------------------------------------
----------------------------------------
data DataOriginApi = InternalOrigin { api :: Database }
data DataOriginApi = InternalOrigin { api :: Database }
...
@@ -91,19 +87,19 @@ instance JSON.WriteForeign DataOriginApi where
...
@@ -91,19 +87,19 @@ instance JSON.WriteForeign DataOriginApi where
writeImpl (ExternalOrigin { api }) = JSON.writeImpl { api }
writeImpl (ExternalOrigin { api }) = JSON.writeImpl { api }
datafield2dataOriginApi :: DataField -> DataOriginApi
datafield2dataOriginApi :: DataField -> DataOriginApi
datafield2dataOriginApi (External
(Just a)
) = ExternalOrigin { api : a }
datafield2dataOriginApi (External
a
) = ExternalOrigin { api : a }
datafield2dataOriginApi _
= InternalOrigin { api : IsTex } -- TODO fixme
datafield2dataOriginApi _
= InternalOrigin { api : IsTex } -- TODO fixme
------------------------------------------------------------------------
------------------------------------------------------------------------
-- | Database search specifications
-- | Database search specifications
datafield2database :: DataField -> Database
datafield2database :: DataField -> Database
datafield2database (External
(Just x)
) = x
datafield2database (External
x
) = x
datafield2database _
= Empty
datafield2database _ = Empty
allDatabases :: Array Database
allDatabases :: Array Database
allDatabases = [ Empty
allDatabases = [ Empty
, PubMed
, PubMed
{ api_key: Nothing }
, Arxiv
, Arxiv
, HAL Nothing
, HAL Nothing
, IsTex
, IsTex
...
@@ -116,7 +112,7 @@ allDatabases = [ Empty
...
@@ -116,7 +112,7 @@ allDatabases = [ Empty
data Database = All_Databases
data Database = All_Databases
| Empty
| Empty
| PubMed
| PubMed
{ api_key :: Maybe String }
| Arxiv
| Arxiv
| HAL (Maybe Org)
| HAL (Maybe Org)
| IsTex
| IsTex
...
@@ -127,7 +123,7 @@ data Database = All_Databases
...
@@ -127,7 +123,7 @@ data Database = All_Databases
derive instance Generic Database _
derive instance Generic Database _
instance Show Database where
instance Show Database where
show All_Databases = "All Databases"
show All_Databases = "All Databases"
show
PubMed
= "PubMed"
show
(PubMed _)
= "PubMed"
show Arxiv = "Arxiv"
show Arxiv = "Arxiv"
show (HAL _) = "HAL"
show (HAL _) = "HAL"
show IsTex = "IsTex"
show IsTex = "IsTex"
...
@@ -139,7 +135,7 @@ instance Show Database where
...
@@ -139,7 +135,7 @@ instance Show Database where
instance Doc Database where
instance Doc Database where
doc All_Databases = "All databases"
doc All_Databases = "All databases"
doc
PubMed
= "All Medical publications"
doc
(PubMed _)
= "All Medical publications"
doc Arxiv = "Arxiv"
doc Arxiv = "Arxiv"
doc (HAL _) = "All open science (archives ouvertes)"
doc (HAL _) = "All open science (archives ouvertes)"
doc IsTex = "All Elsevier enriched by CNRS/INIST"
doc IsTex = "All Elsevier enriched by CNRS/INIST"
...
@@ -149,22 +145,46 @@ instance Doc Database where
...
@@ -149,22 +145,46 @@ instance Doc Database where
-- doc News = "Web filtered by News"
-- doc News = "Web filtered by News"
-- doc SocialNetworks = "Web filtered by MicroBlogs"
-- doc SocialNetworks = "Web filtered by MicroBlogs"
instance Read Database where
-- instance Read Database where
read :: String -> Maybe Database
-- read :: String -> Maybe Database
read "All Databases" = Just All_Databases
-- read "All Databases" = Just All_Databases
read "PubMed" = Just PubMed
-- read "PubMed" = Just PubMed
read "Arxiv" = Just Arxiv
-- read "Arxiv" = Just Arxiv
read "HAL" = Just $ HAL Nothing
-- read "HAL" = Just $ HAL Nothing
read "Isidore" = Just Isidore
-- read "Isidore" = Just Isidore
read "IsTex" = Just IsTex
-- read "IsTex" = Just IsTex
read "IsTex_Advanced" = Just IsTex_Advanced
-- read "IsTex_Advanced" = Just IsTex_Advanced
-- read "Web" = Just Web
-- -- read "Web" = Just Web
-- read "News" = Just News
-- -- read "News" = Just News
-- read "Social Networks" = Just SocialNetworks
-- -- read "Social Networks" = Just SocialNetworks
read _ = Nothing
-- read _ = Nothing
dbToInputValue :: Database -> String
dbToInputValue All_Databases = "all_databases"
dbToInputValue (PubMed _) = "pubmed"
dbToInputValue Arxiv = "arxiv"
dbToInputValue (HAL _) = "hal"
dbToInputValue IsTex = "istex"
dbToInputValue IsTex_Advanced = "istex_advanced"
dbToInputValue Isidore = "isidore"
dbToInputValue Empty = "empty"
dbFromInputValue :: String -> Maybe Database
dbFromInputValue "all_databases" = Just All_Databases
dbFromInputValue "pubmed" = Just (PubMed { api_key: Nothing})
dbFromInputValue "arxiv" = Just Arxiv
dbFromInputValue "hal" = Just (HAL Nothing)
dbFromInputValue "istex" = Just IsTex
dbFromInputValue "istex_advanced" = Just IsTex_Advanced
dbFromInputValue "isidore" = Just Isidore
dbFromInputValue "empty" = Just Empty
dbFromInputValue _ = Nothing
derive instance Eq Database
derive instance Eq Database
instance JSON.WriteForeign Database where writeImpl = JSON.writeImpl <<< show
instance JSON.WriteForeign Database where
writeImpl (PubMed { api_key }) = JSON.writeImpl { tag: "PubMed"
, _api_key: api_key }
writeImpl f = JSON.writeImpl { tag: show f }
------------------------------------------------------------------------
------------------------------------------------------------------------
-- | Organization specifications
-- | Organization specifications
...
@@ -234,16 +254,17 @@ instance Show SearchOrder where
...
@@ -234,16 +254,17 @@ instance Show SearchOrder where
------------------------------------------------------------------------
------------------------------------------------------------------------
newtype SearchQuery = SearchQuery
newtype SearchQuery = SearchQuery
{ query :: String
{ query :: String
, databases :: Database
, databases :: Database
, datafield :: Maybe DataField
, datafield :: Maybe DataField
, files_id :: Array String
, files_id :: Array String
, lang :: Maybe Lang
, lang :: Maybe Lang
, limit :: Maybe Int
, limit :: Maybe Int
, node_id :: Maybe Int
, node_id :: Maybe Int
, offset :: Maybe Int
, offset :: Maybe Int
, order :: Maybe SearchOrder
, order :: Maybe SearchOrder
, selection :: ListSelection.Selection
, pubmedAPIKey :: Maybe String
, selection :: ListSelection.Selection
}
}
derive instance Generic SearchQuery _
derive instance Generic SearchQuery _
derive instance Newtype SearchQuery _
derive instance Newtype SearchQuery _
...
@@ -260,27 +281,29 @@ instance GT.ToQuery SearchQuery where
...
@@ -260,27 +281,29 @@ instance GT.ToQuery SearchQuery where
pair k = maybe [] $ \v ->
pair k = maybe [] $ \v ->
[ QP.keyFromString k /\ Just (QP.valueFromString $ show v) ]
[ QP.keyFromString k /\ Just (QP.valueFromString $ show v) ]
instance JSON.WriteForeign SearchQuery where
instance JSON.WriteForeign SearchQuery where
writeImpl (SearchQuery { databases, datafield, lang, node_id, query, selection }) =
writeImpl (SearchQuery { databases, datafield, lang, node_id,
pubmedAPIKey,
query, selection }) =
JSON.writeImpl { query: query -- String.replace (String.Pattern "\"") (String.Replacement "\\\"") query
JSON.writeImpl { query: query -- String.replace (String.Pattern "\"") (String.Replacement "\\\"") query
, databases
, databases
, datafield
, datafield
, lang: maybe "EN" show lang
, lang: maybe "EN" show lang
, node_id: fromMaybe 0 node_id
, node_id: fromMaybe 0 node_id
, flowListWith: selection
, flowListWith: selection
, pubmedAPIKey
}
}
defaultSearchQuery :: SearchQuery
defaultSearchQuery :: SearchQuery
defaultSearchQuery = SearchQuery
defaultSearchQuery = SearchQuery
{ query : ""
{ query : ""
, databases : Empty
, databases : Empty
, datafield : Nothing
, datafield : Nothing
, files_id : []
, files_id : []
, lang : Nothing
, lang : Nothing
, limit : Nothing
, limit : Nothing
, node_id : Nothing
, node_id : Nothing
, offset : Nothing
, offset : Nothing
, order : Nothing
, order : Nothing
, selection : ListSelection.NoList -- MyListsFirst
, pubmedAPIKey : Nothing
, selection : ListSelection.NoList -- MyListsFirst
}
}
performSearch :: Session -> Int -> SearchQuery -> AffRESTError GT.AsyncTaskWithType
performSearch :: Session -> Int -> SearchQuery -> AffRESTError GT.AsyncTaskWithType
...
...
src/Gargantext/Components/GraphQL.purs
View file @
6500552a
...
@@ -14,7 +14,7 @@ import Gargantext.Components.GraphQL.Contact (AnnuaireContact)
...
@@ -14,7 +14,7 @@ import Gargantext.Components.GraphQL.Contact (AnnuaireContact)
import Gargantext.Components.GraphQL.Context as GQLCTX
import Gargantext.Components.GraphQL.Context as GQLCTX
import Gargantext.Components.GraphQL.IMT as GQLIMT
import Gargantext.Components.GraphQL.IMT as GQLIMT
import Gargantext.Components.GraphQL.NLP as GQLNLP
import Gargantext.Components.GraphQL.NLP as GQLNLP
import Gargantext.Components.GraphQL.Node
(Node)
import Gargantext.Components.GraphQL.Node
as GQLNode
import Gargantext.Components.GraphQL.Tree (TreeFirstLevel)
import Gargantext.Components.GraphQL.Tree (TreeFirstLevel)
import Gargantext.Components.GraphQL.User (User, UserInfo, UserInfoM)
import Gargantext.Components.GraphQL.User (User, UserInfo, UserInfoM)
import Gargantext.Components.GraphQL.Team (Team, TeamDeleteM)
import Gargantext.Components.GraphQL.Team (Team, TeamDeleteM)
...
@@ -78,8 +78,9 @@ type Schema
...
@@ -78,8 +78,9 @@ type Schema
, contexts_for_ngrams :: { corpus_id :: Int, ngrams_terms :: Array String } ==> Array GQLCTX.Context
, contexts_for_ngrams :: { corpus_id :: Int, ngrams_terms :: Array String } ==> Array GQLCTX.Context
, imt_schools :: {} ==> Array GQLIMT.School
, imt_schools :: {} ==> Array GQLIMT.School
, languages :: {} ==> Array GQLNLP.Language
, languages :: {} ==> Array GQLNLP.Language
, node_parent :: { node_id :: Int, parent_type :: String } ==> Array Node -- TODO: parent_type :: NodeType
, node_parent :: { node_id :: Int, parent_type :: String } ==> Array GQLNode.Node -- TODO: parent_type :: NodeType
, nodes :: { node_id :: Int } ==> Array Node
, nodes :: { node_id :: Int } ==> Array GQLNode.Node
, nodes_corpus :: { corpus_id :: Int } ==> Array GQLNode.Corpus
, user_infos :: { user_id :: Int } ==> Array UserInfo
, user_infos :: { user_id :: Int } ==> Array UserInfo
, users :: { user_id :: Int } ==> Array User
, users :: { user_id :: Int } ==> Array User
, team :: { team_node_id :: Int } ==> Team
, team :: { team_node_id :: Int } ==> Team
...
...
src/Gargantext/Components/GraphQL/Endpoints.purs
View file @
6500552a
...
@@ -14,7 +14,7 @@ import Gargantext.Components.GraphQL.Contact (AnnuaireContact, annuaireContactQu
...
@@ -14,7 +14,7 @@ import Gargantext.Components.GraphQL.Contact (AnnuaireContact, annuaireContactQu
import Gargantext.Components.GraphQL.Context as GQLCTX
import Gargantext.Components.GraphQL.Context as GQLCTX
import Gargantext.Components.GraphQL.IMT as GQLIMT
import Gargantext.Components.GraphQL.IMT as GQLIMT
import Gargantext.Components.GraphQL.NLP as GQLNLP
import Gargantext.Components.GraphQL.NLP as GQLNLP
import Gargantext.Components.GraphQL.Node (
Node, nodeParentQuery, node
sQuery)
import Gargantext.Components.GraphQL.Node (
Corpus, Node, nodeParentQuery, nodesQuery, nodesCorpu
sQuery)
import Gargantext.Components.GraphQL.Team (Team, teamQuery)
import Gargantext.Components.GraphQL.Team (Team, teamQuery)
import Gargantext.Components.GraphQL.Tree (TreeFirstLevel, treeFirstLevelQuery)
import Gargantext.Components.GraphQL.Tree (TreeFirstLevel, treeFirstLevelQuery)
import Gargantext.Components.GraphQL.User (UserInfo, userInfoQuery)
import Gargantext.Components.GraphQL.User (UserInfo, userInfoQuery)
...
@@ -46,6 +46,15 @@ getNode session nodeId = do
...
@@ -46,6 +46,15 @@ getNode session nodeId = do
Nothing -> Left (CustomError $ "node with id" <> show nodeId <>" not found")
Nothing -> Left (CustomError $ "node with id" <> show nodeId <>" not found")
Just node -> Right node
Just node -> Right node
getNodeCorpus :: Session -> Int -> AffRESTError Corpus
getNodeCorpus session corpusId = do
{ nodes_corpus } <- queryGql session "get nodes corpus" $
nodesCorpusQuery `withVars` { id: corpusId }
liftEffect $ here.log2 "[getNodesCorpus] nodes_corpus" nodes_corpus
pure $ case A.head nodes_corpus of
Nothing -> Left (CustomError $ "corpus with id" <> show corpusId <>" not found")
Just corpus -> Right corpus
getNodeParent :: Session -> Int -> NodeType -> Aff (Array Node)
getNodeParent :: Session -> Int -> NodeType -> Aff (Array Node)
getNodeParent session nodeId parentType = do
getNodeParent session nodeId parentType = do
{ node_parent } <- queryGql session "get node parent" $
{ node_parent } <- queryGql session "get node parent" $
...
...
src/Gargantext/Components/GraphQL/Node.purs
View file @
6500552a
...
@@ -2,18 +2,35 @@ module Gargantext.Components.GraphQL.Node where
...
@@ -2,18 +2,35 @@ module Gargantext.Components.GraphQL.Node where
import Gargantext.Prelude
import Gargantext.Prelude
import Data.Maybe (Maybe)
import GraphQL.Client.Args (Args, (=>>))
import GraphQL.Client.Args (Args, (=>>))
import GraphQL.Client.Variable (Var(..))
import GraphQL.Client.Variable (Var(..))
import Gargantext.Utils.GraphQL as GGQL
import Gargantext.Utils.GraphQL as GGQL
import Type.Proxy (Proxy(..))
import Type.Proxy (Proxy(..))
type Corpus
= { id :: Int
, name :: String
, parent_id :: Int
, pubmedAPIKey :: Maybe String
, type_id :: Int }
type Node
type Node
= { id :: Int
= { id :: Int
, name :: String
, name :: String
, parent_id :: Int
, parent_id :: Int
, type_id :: Int }
, type_id :: Int }
type NodesCorpusQuery =
{ nodes_corpus :: Args
{ corpus_id :: Var "id" Int }
{ id :: Unit
, name :: Unit
, parent_id :: Unit
, pubmedAPIKey :: Unit
, type_id :: Unit } }
type NodesQuery =
type NodesQuery =
{ nodes :: Args
{ nodes :: Args
{ node_id :: Var "id" Int }
{ node_id :: Var "id" Int }
...
@@ -27,6 +44,11 @@ nodesQuery = { nodes: { node_id: Var :: _ "id" Int } =>>
...
@@ -27,6 +44,11 @@ nodesQuery = { nodes: { node_id: Var :: _ "id" Int } =>>
GGQL.getFieldsStandard (Proxy :: _ Node)
GGQL.getFieldsStandard (Proxy :: _ Node)
}
}
nodesCorpusQuery :: NodesCorpusQuery
nodesCorpusQuery = { nodes_corpus: { corpus_id: Var :: _ "id" Int } =>>
GGQL.getFieldsStandard (Proxy :: _ Corpus)
}
nodeParentQuery = { node_parent: { node_id: Var :: _ "id" Int
nodeParentQuery = { node_parent: { node_id: Var :: _ "id" Int
, parent_type: Var :: _ "parent_type" String } =>> -- TODO parent_type :: NodeType
, parent_type: Var :: _ "parent_type" String } =>> -- TODO parent_type :: NodeType
GGQL.getFieldsStandard (Proxy :: _ Node)
GGQL.getFieldsStandard (Proxy :: _ Node)
...
...
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