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)
import Data.Newtype (class Newtype)
import Data.Set (Set)
import Data.Set as Set
import Data.String as String
import Data.Tuple (Tuple)
import Data.Tuple.Nested ((/\))
import Gargantext.Components.GraphQL.IMT as GQLIMT
...
...
@@ -23,21 +22,18 @@ import Simple.JSON as JSON
import URI.Extra.QueryPairs as QP
import URI.Query as Q
type Search = { databases :: Database
, datafield :: Maybe DataField
, url :: String
, lang :: Maybe Lang
, node_id :: Maybe Int
, term :: String
, years :: Array String
type Search = { databases
:: Database
, datafield
:: Maybe DataField
, url
:: String
, lang
:: Maybe Lang
, node_id
:: Maybe Int
, term
:: String
, years
:: Array String
}
isIsTex_Advanced :: Maybe DataField -> Boolean
isIsTex_Advanced ( Just
( External
( Just ( IsTex_Advanced)
)
)
( External ( IsTex_Advanced) )
) = true
isIsTex_Advanced _ = false
...
...
@@ -51,13 +47,13 @@ class Doc a where
dataFields :: Array DataField
dataFields = [ {- Gargantext
, -} External
Nothing
, -} External
Empty
, Web
-- , Files
]
data DataField = Gargantext
| External
(Maybe Database)
| External
Database
| Web
| Files
...
...
@@ -74,9 +70,9 @@ instance Doc DataField where
doc Files = "Zip files with formats.."
derive instance Eq DataField
instance JSON.WriteForeign DataField where
writeImpl (External
(Just db)) = JSON.writeImpl $ "External " <> show db
writeImpl Web = JSON.writeImpl $ "Web"
writeImpl f = JSON.writeImpl $
show f
writeImpl (External
db) = JSON.writeImpl { tag: "External"
, contents: JSON.writeImpl db }
writeImpl f = JSON.writeImpl $
JSON.writeImpl { tag: show f }
----------------------------------------
data DataOriginApi = InternalOrigin { api :: Database }
...
...
@@ -91,19 +87,19 @@ instance JSON.WriteForeign DataOriginApi where
writeImpl (ExternalOrigin { api }) = JSON.writeImpl { api }
datafield2dataOriginApi :: DataField -> DataOriginApi
datafield2dataOriginApi (External
(Just a)
) = ExternalOrigin { api : a }
datafield2dataOriginApi _
= InternalOrigin { api : IsTex } -- TODO fixme
datafield2dataOriginApi (External
a
) = ExternalOrigin { api : a }
datafield2dataOriginApi _
= InternalOrigin { api : IsTex } -- TODO fixme
------------------------------------------------------------------------
-- | Database search specifications
datafield2database :: DataField -> Database
datafield2database (External
(Just x)
) = x
datafield2database _
= Empty
datafield2database (External
x
) = x
datafield2database _ = Empty
allDatabases :: Array Database
allDatabases = [ Empty
, PubMed
, PubMed
{ api_key: Nothing }
, Arxiv
, HAL Nothing
, IsTex
...
...
@@ -116,7 +112,7 @@ allDatabases = [ Empty
data Database = All_Databases
| Empty
| PubMed
| PubMed
{ api_key :: Maybe String }
| Arxiv
| HAL (Maybe Org)
| IsTex
...
...
@@ -127,7 +123,7 @@ data Database = All_Databases
derive instance Generic Database _
instance Show Database where
show All_Databases = "All Databases"
show
PubMed
= "PubMed"
show
(PubMed _)
= "PubMed"
show Arxiv = "Arxiv"
show (HAL _) = "HAL"
show IsTex = "IsTex"
...
...
@@ -139,7 +135,7 @@ instance Show Database where
instance Doc Database where
doc All_Databases = "All databases"
doc
PubMed
= "All Medical publications"
doc
(PubMed _)
= "All Medical publications"
doc Arxiv = "Arxiv"
doc (HAL _) = "All open science (archives ouvertes)"
doc IsTex = "All Elsevier enriched by CNRS/INIST"
...
...
@@ -149,22 +145,46 @@ instance Doc Database where
-- doc News = "Web filtered by News"
-- doc SocialNetworks = "Web filtered by MicroBlogs"
instance Read Database where
read :: String -> Maybe Database
read "All Databases" = Just All_Databases
read "PubMed" = Just PubMed
read "Arxiv" = Just Arxiv
read "HAL" = Just $ HAL Nothing
read "Isidore" = Just Isidore
read "IsTex" = Just IsTex
read "IsTex_Advanced" = Just IsTex_Advanced
-- read "Web" = Just Web
-- read "News" = Just News
-- read "Social Networks" = Just SocialNetworks
read _ = Nothing
-- instance Read Database where
-- read :: String -> Maybe Database
-- read "All Databases" = Just All_Databases
-- read "PubMed" = Just PubMed
-- read "Arxiv" = Just Arxiv
-- read "HAL" = Just $ HAL Nothing
-- read "Isidore" = Just Isidore
-- read "IsTex" = Just IsTex
-- read "IsTex_Advanced" = Just IsTex_Advanced
-- -- read "Web" = Just Web
-- -- read "News" = Just News
-- -- read "Social Networks" = Just SocialNetworks
-- 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
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
...
...
@@ -234,16 +254,17 @@ instance Show SearchOrder where
------------------------------------------------------------------------
newtype SearchQuery = SearchQuery
{ query :: String
, databases :: Database
, datafield :: Maybe DataField
, files_id :: Array String
, lang :: Maybe Lang
, limit :: Maybe Int
, node_id :: Maybe Int
, offset :: Maybe Int
, order :: Maybe SearchOrder
, selection :: ListSelection.Selection
{ query :: String
, databases :: Database
, datafield :: Maybe DataField
, files_id :: Array String
, lang :: Maybe Lang
, limit :: Maybe Int
, node_id :: Maybe Int
, offset :: Maybe Int
, order :: Maybe SearchOrder
, pubmedAPIKey :: Maybe String
, selection :: ListSelection.Selection
}
derive instance Generic SearchQuery _
derive instance Newtype SearchQuery _
...
...
@@ -260,27 +281,29 @@ instance GT.ToQuery SearchQuery where
pair k = maybe [] $ \v ->
[ QP.keyFromString k /\ Just (QP.valueFromString $ show v) ]
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
, databases
, datafield
, lang: maybe "EN" show lang
, node_id: fromMaybe 0 node_id
, flowListWith: selection
, pubmedAPIKey
}
defaultSearchQuery :: SearchQuery
defaultSearchQuery = SearchQuery
{ query : ""
, databases : Empty
, datafield : Nothing
, files_id : []
, lang : Nothing
, limit : Nothing
, node_id : Nothing
, offset : Nothing
, order : Nothing
, selection : ListSelection.NoList -- MyListsFirst
{ query : ""
, databases : Empty
, datafield : Nothing
, files_id : []
, lang : Nothing
, limit : Nothing
, node_id : Nothing
, offset : Nothing
, order : Nothing
, pubmedAPIKey : Nothing
, selection : ListSelection.NoList -- MyListsFirst
}
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)
import Gargantext.Components.GraphQL.Context as GQLCTX
import Gargantext.Components.GraphQL.IMT as GQLIMT
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.User (User, UserInfo, UserInfoM)
import Gargantext.Components.GraphQL.Team (Team, TeamDeleteM)
...
...
@@ -78,8 +78,9 @@ type Schema
, contexts_for_ngrams :: { corpus_id :: Int, ngrams_terms :: Array String } ==> Array GQLCTX.Context
, imt_schools :: {} ==> Array GQLIMT.School
, languages :: {} ==> Array GQLNLP.Language
, node_parent :: { node_id :: Int, parent_type :: String } ==> Array Node -- TODO: parent_type :: NodeType
, nodes :: { node_id :: Int } ==> Array Node
, node_parent :: { node_id :: Int, parent_type :: String } ==> Array GQLNode.Node -- TODO: parent_type :: NodeType
, nodes :: { node_id :: Int } ==> Array GQLNode.Node
, nodes_corpus :: { corpus_id :: Int } ==> Array GQLNode.Corpus
, user_infos :: { user_id :: Int } ==> Array UserInfo
, users :: { user_id :: Int } ==> Array User
, 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
import Gargantext.Components.GraphQL.Context as GQLCTX
import Gargantext.Components.GraphQL.IMT as GQLIMT
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.Tree (TreeFirstLevel, treeFirstLevelQuery)
import Gargantext.Components.GraphQL.User (UserInfo, userInfoQuery)
...
...
@@ -46,6 +46,15 @@ getNode session nodeId = do
Nothing -> Left (CustomError $ "node with id" <> show nodeId <>" not found")
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 nodeId parentType = do
{ 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
import Gargantext.Prelude
import Data.Maybe (Maybe)
import GraphQL.Client.Args (Args, (=>>))
import GraphQL.Client.Variable (Var(..))
import Gargantext.Utils.GraphQL as GGQL
import Type.Proxy (Proxy(..))
type Corpus
= { id :: Int
, name :: String
, parent_id :: Int
, pubmedAPIKey :: Maybe String
, type_id :: Int }
type Node
= { id :: Int
, name :: String
, parent_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 =
{ nodes :: Args
{ node_id :: Var "id" Int }
...
...
@@ -27,6 +44,11 @@ nodesQuery = { nodes: { node_id: Var :: _ "id" Int } =>>
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
, parent_type: Var :: _ "parent_type" String } =>> -- TODO parent_type :: NodeType
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