Squashed commit of the following:

commit ea934d83
Author: Przemysław Kaminski <pk@intrepidus.pl>
Date:   Tue Jan 14 06:59:11 2025 +0100

    [search] move EPO user/token into the datafield

commit b01a85eb
Author: Przemysław Kaminski <pk@intrepidus.pl>
Date:   Mon Jan 13 10:15:27 2025 +0100

    [search] search query json format fixes

    Related to haskell-gargantext#441

    Related to commmit
    haskell-gargantext@bc29319c

commit 3b50603a
Merge: a93e055b 2e43c474
Author: Przemysław Kaminski <pk@intrepidus.pl>
Date:   Fri Jan 10 12:04:36 2025 +0100

    Merge branch 'dev' into 204-ngrams-refactor-fixes

commit a93e055b
Author: Przemysław Kaminski <pk@intrepidus.pl>
Date:   Wed Jan 8 18:22:37 2025 +0100

    [search] pubmed constructor with api key

This commit has to be merged together with
haskell-gargantext!385 (03b33383)
parent 2e43c474
Pipeline #7290 passed with stages
in 18 minutes and 7 seconds
......@@ -55,7 +55,7 @@ searchIframesCpt = here.component "searchIframes" cpt
pure $
if isIsTex_Advanced search'.datafield then divIframe { frameSource: Istex, iframeRef, search } []
else if Just Web == search'.datafield then divIframe { frameSource: Searx, iframeRef, search } []
else if Web == search'.datafield then divIframe { frameSource: Searx, iframeRef, search } []
else H.div {} []
type IFrameProps =
......
......@@ -36,12 +36,8 @@ here = R2.here "Gargantext.Components.Forest.Tree.Node.Action.Search.SearchField
defaultSearch :: Search
defaultSearch =
{ databases: Empty
, datafield: Just (External Empty)
{ datafield: External Empty
, node_id: Nothing
, epoApiUser: Nothing
, epoApiToken: Nothing
, pubmedApiKey: Nothing
, lang: Nothing
, term: ""
, url: ""
......@@ -202,93 +198,73 @@ componentCNRSCpt = here.component "componentCNRS" cpt
--, filterInput fi
]
isExternal :: Maybe DataField -> Boolean
isExternal (Just (External _)) = true
isExternal :: DataField -> Boolean
isExternal (External _) = true
isExternal _ = false
isArxiv :: Maybe DataField -> Boolean
isArxiv
( Just
(External Arxiv)
) = true
isArxiv :: DataField -> Boolean
isArxiv (External Arxiv) = true
isArxiv _ = false
isHAL :: Maybe DataField -> Boolean
isHAL
( Just
(External (HAL _))
) = true
isHAL :: DataField -> Boolean
isHAL (External (HAL _)) = true
isHAL _ = false
isIsTex :: Maybe DataField -> Boolean
isIsTex
( Just
(External (IsTex))
) = true
isIsTex :: DataField -> Boolean
isIsTex (External (IsTex)) = true
isIsTex _ = false
isIMT :: Maybe DataField -> Boolean
isIMT :: DataField -> Boolean
isIMT
( Just
( External
( HAL
(Just (IMT _))
)
( External
( HAL
(Just (IMT _))
)
) = true
isIMT _ = false
isCNRS :: Maybe DataField -> Boolean
isCNRS :: DataField -> Boolean
isCNRS
( Just
( External
( HAL
(Just (CNRS _))
)
( External
( HAL
(Just (CNRS _))
)
) = true
isCNRS _ = false
isPubmed :: Maybe DataField -> Boolean
isPubmed
( Just
(External PubMed)
) = true
isPubmed :: DataField -> Boolean
isPubmed (External (PubMed _)) = true
isPubmed _ = false
isEPO :: Maybe DataField -> Boolean
isEPO
( Just
(External EPO)
) = true
getPubmedAPIKey :: DataField -> Maybe String
getPubmedAPIKey (External (PubMed mAPI)) = mAPI
getPubmedAPIKey _ = Nothing
isEPO :: DataField -> Boolean
isEPO (External (EPO _ _)) = true
isEPO _ = false
needsLang :: Maybe DataField -> Boolean
needsLang (Just Gargantext) = true
needsLang (Just Web) = true
needsLang
( Just
(External (HAL _))
) = true
needsLang :: DataField -> Boolean
needsLang Gargantext = true
needsLang Web = true
needsLang (External (HAL _)) = true
needsLang _ = false
isIn :: IMT_org -> Maybe DataField -> Boolean
isIn :: IMT_org -> DataField -> Boolean
isIn
org
( Just
( External
( HAL
( Just
(IMT imtOrgs)
)
( External
( HAL
( Just
(IMT imtOrgs)
)
)
) = Set.member org imtOrgs
isIn _ _ = false
updateFilter :: IMT_org -> Array IMT_org -> Maybe DataField -> Maybe DataField
updateFilter org allIMTorgs (Just (External (HAL (Just (IMT imtOrgs))))) =
Just $ External $ HAL $ Just $ IMT imtOrgs'
updateFilter :: IMT_org -> Array IMT_org -> DataField -> DataField
updateFilter org allIMTorgs (External (HAL (Just (IMT imtOrgs)))) =
External $ HAL $ Just $ IMT imtOrgs'
where
imtOrgs' =
if Set.member org imtOrgs then
......@@ -297,7 +273,7 @@ updateFilter org allIMTorgs (Just (External (HAL (Just (IMT imtOrgs))))) =
else if org == All_IMT then Set.fromFoldable allIMTorgs
else Set.insert org imtOrgs
updateFilter org allIMTorgs _ = (Just (External (HAL (Just (IMT imtOrgs')))))
updateFilter org allIMTorgs _ = (External (HAL (Just (IMT imtOrgs'))))
where
imtOrgs' =
if org == All_IMT then Set.fromFoldable allIMTorgs
......@@ -350,8 +326,7 @@ dataFieldNavCpt = here.component "dataFieldNav" cpt
[ H.div { className: "text-primary text-bold p-1" } [ H.text "Search options:" ]
, H.div { className: "nav nav-tabs" } ((liItem search') <$> dataFields)
, H.div { className: "center p-1" }
[ H.text
$ maybe "TODO: add Doc Instance" doc datafield
[ H.text $ doc datafield
]
]
where
......@@ -366,8 +341,7 @@ dataFieldNavCpt = here.component "dataFieldNav" cpt
, on:
{ click: \_ -> T.modify_
( _
{ datafield = Just df'
, databases = datafield2database df'
{ datafield = df'
}
)
search
......@@ -401,7 +375,7 @@ databaseInputCpt = here.component "databaseInput" cpt
let
db = case search'.datafield of
(Just (External x)) -> Just x
(External x) -> Just x
_ -> Nothing
dbInputValue = fromMaybe "" $ dbToInputValue <$> db
......@@ -420,8 +394,7 @@ databaseInputCpt = here.component "databaseInput" cpt
T.modify_
( _
{ datafield = Just $ External updatedValue
, databases = updatedValue
{ datafield = External updatedValue
}
)
search
......@@ -477,15 +450,16 @@ pubmedInputLoadedCpt = here.component "pubmedInputLoaded" cpt
search' <- T.useLive T.unequal search
R.useEffectOnce' $ do
when (search'.pubmedApiKey /= pubmedAPIKey) $ do
T.write_ (search' { pubmedApiKey = pubmedAPIKey }) search
when (getPubmedAPIKey search'.datafield /= pubmedAPIKey) $ do
T.modify_ (\s -> s { datafield = External $ PubMed pubmedAPIKey }) search
-- T.write_ (search' { pubmedApiKey = pubmedAPIKey }) search
pure $
H.div { className: "form-group p-1 m-0" }
[ H.div { className: "text-primary center" } [ H.text "Pubmed API key" ]
, H.input
{ className: "form-control"
, defaultValue: fromMaybe "" search'.pubmedApiKey
, defaultValue: fromMaybe "" pubmedAPIKey
, on:
{ blur: modifyPubmedAPIKey search
, change: modifyPubmedAPIKey search
......@@ -502,7 +476,7 @@ pubmedInputLoadedCpt = here.component "pubmedInputLoaded" cpt
s -> Just s
T.modify_
( \s ->
s { pubmedApiKey = mVal }
s { datafield = External $ PubMed mVal }
)
searchS
......@@ -537,6 +511,14 @@ type EPOInputLoadedProps =
, search :: T.Box Search
)
searchEPOAPIUser :: Search -> Maybe String
searchEPOAPIUser { datafield: External (EPO mAPIUser _) } = mAPIUser
searchEPOAPIUser _ = Nothing
searchEPOAPIToken :: Search -> Maybe String
searchEPOAPIToken { datafield: External (EPO _ mAPIToken) } = mAPIToken
searchEPOAPIToken _ = Nothing
epoInputLoaded :: R2.Component EPOInputLoadedProps
epoInputLoaded = R.createElement epoInputLoadedCpt
......@@ -547,11 +529,10 @@ epoInputLoadedCpt = here.component "epoInputLoaded" cpt
search' <- T.useLive T.unequal search
R.useEffectOnce' $ do
when (search'.epoApiUser /= epoAPIUser || search'.epoApiToken /= epoAPIToken) $ do
when (searchEPOAPIUser search' /= epoAPIUser || searchEPOAPIToken search' /= epoAPIToken) $ do
T.write_
( search'
{ epoApiUser = epoAPIUser
, epoApiToken = epoAPIToken
{ datafield = External (EPO epoAPIUser epoAPIToken)
}
)
search
......@@ -561,7 +542,7 @@ epoInputLoadedCpt = here.component "epoInputLoaded" cpt
[ H.div { className: "text-primary center" } [ H.text "EPO API User" ]
, H.input
{ className: "form-control"
, defaultValue: fromMaybe "" search'.epoApiUser
, defaultValue: fromMaybe "" $ searchEPOAPIUser search'
, on:
{ blur: modifyEPOAPIUser search
, change: modifyEPOAPIUser search
......@@ -571,7 +552,7 @@ epoInputLoadedCpt = here.component "epoInputLoaded" cpt
, H.div { className: "text-primary center" } [ H.text "EPO API Token" ]
, H.input
{ className: "form-control"
, defaultValue: fromMaybe "" search'.epoApiToken
, defaultValue: fromMaybe "" $ searchEPOAPIToken search'
, on:
{ blur: modifyEPOAPIToken search
, change: modifyEPOAPIToken search
......@@ -586,7 +567,7 @@ epoInputLoadedCpt = here.component "epoInputLoaded" cpt
mVal = case val of
"" -> Nothing
s -> Just s
T.modify_ (\s -> s { epoApiUser = mVal }) searchS
T.modify_ (\s -> s { datafield = External (EPO mVal (searchEPOAPIToken s)) }) searchS
modifyEPOAPIToken searchS e = do
let val = R.unsafeEventValue e
......@@ -594,7 +575,7 @@ epoInputLoadedCpt = here.component "epoInputLoaded" cpt
mVal = case val of
"" -> Nothing
s -> Just s
T.modify_ (\s -> s { epoApiToken = mVal }) searchS
T.modify_ (\s -> s { datafield = External (EPO (searchEPOAPIUser s) mVal) }) searchS
type OrgInputProps =
( orgs :: Array Org
......@@ -611,7 +592,7 @@ orgInputCpt = here.component "orgInput" cpt
let
change e = do
let value = R.unsafeEventValue e
T.modify_ (_ { datafield = Just $ External $ HAL $ read value }) search
T.modify_ (_ { datafield = External $ HAL $ read value }) search
pure $ H.div { className: "form-group p-1 m-0" }
[ H.div { className: "text-primary center" } [ H.text "filter with organization: " ]
......@@ -685,7 +666,7 @@ datafieldInputCpt = here.component "datafieldInput" cpt
else H.div {} []
, if needsLang search'.datafield then
if search'.datafield == Just Web then
if search'.datafield == Web then
langNav { langs: A.filter (\lang -> lang == FR) langs, search } []
else
langNav { langs, search } []
......@@ -818,19 +799,10 @@ triggerSearch { onSearch, errors, session, selection, search } =
-- modalShow "addCorpus"
searchQuery :: ListSelection.Selection -> Search -> SearchQuery
searchQuery selection { datafield: Nothing, term } =
over SearchQuery
( _
{ query = term
, selection = selection
}
)
defaultSearchQuery
-- TODO Simplify both HAL Nothing and HAL (Just IMT) cases
searchQuery
selection
{ databases
, datafield: datafield@(Just (External (HAL Nothing)))
{ datafield: datafield@(External (HAL Nothing))
, lang
, node_id
, term
......@@ -838,8 +810,7 @@ searchQuery
} =
over SearchQuery
( _
{ databases = databases
, datafield = datafield
{ datafield = datafield
, lang = lang
, node_id = node_id
, query = queryHAL term Nothing lang years
......@@ -850,8 +821,7 @@ searchQuery
searchQuery
selection
{ databases
, datafield: datafield@(Just (External (HAL (Just (IMT imtOrgs)))))
{ datafield: datafield@(External (HAL (Just (IMT imtOrgs))))
, lang
, node_id
, term
......@@ -859,8 +829,7 @@ searchQuery
} =
over SearchQuery
( _
{ databases = databases
, datafield = datafield
{ datafield = datafield
, lang = lang
, node_id = node_id
, query = queryHAL term (Just imtOrgs) lang years
......@@ -868,55 +837,10 @@ searchQuery
}
)
defaultSearchQuery
searchQuery
selection
{ databases
, datafield: datafield@(Just (External EPO))
, lang
, epoApiUser
, epoApiToken
, node_id
, term
} =
over SearchQuery
( _
{ databases = databases
, datafield = datafield
, lang = lang
, node_id = node_id
, epoAPIUser = epoApiUser
, epoAPIToken = epoApiToken
, query = term
, selection = selection
}
)
defaultSearchQuery
searchQuery
selection
{ databases
, datafield: datafield@(Just (External PubMed))
, lang
, pubmedApiKey
, node_id
, term
} =
over SearchQuery
( _
{ databases = databases
, datafield = datafield
, lang = lang
, node_id = node_id
, pubmedAPIKey = pubmedApiKey
, query = term
, selection = selection
}
)
defaultSearchQuery
searchQuery selection { databases, datafield, lang, term, node_id } =
searchQuery selection { datafield, lang, term, node_id } =
over SearchQuery
( _
{ databases = databases
, datafield = datafield
{ datafield = datafield
, lang = lang
, node_id = node_id
, query = term
......
......@@ -2,6 +2,7 @@ module Gargantext.Components.Forest.Tree.Node.Action.Search.Types where
import Gargantext.Prelude
import Data.Array as A
-- import Data.Bounded (class Bounded)
import Data.Either (Either)
-- import Data.Enum (class Enum, class BoundedEnum)
......@@ -26,23 +27,16 @@ import URI.Extra.QueryPairs as QP
import URI.Query as Q
type Search =
{ databases :: Database
, datafield :: Maybe DataField
{ datafield :: DataField
, url :: String
, lang :: Maybe Lang
, node_id :: Maybe Int
, epoApiUser :: Maybe String
, epoApiToken :: Maybe String
, pubmedApiKey :: Maybe String
, term :: String
, years :: Array String
}
isIsTex_Advanced :: Maybe DataField -> Boolean
isIsTex_Advanced
( Just
(External (IsTex_Advanced))
) = true
isIsTex_Advanced :: DataField -> Boolean
isIsTex_Advanced (External (IsTex_Advanced)) = true
isIsTex_Advanced _ = false
------------------------------------------------------------------------
......@@ -81,7 +75,7 @@ instance Doc DataField where
derive instance Eq DataField
instance JSON.WriteForeign DataField where
writeImpl (External db) = JSON.writeImpl { "External": JSON.writeImpl $ show db }
writeImpl (External db) = JSON.writeImpl { "External": db }
writeImpl Gargantext = JSON.writeImpl "Gargantext"
writeImpl Web = JSON.writeImpl "Web"
writeImpl Files = JSON.writeImpl "Files"
......@@ -116,13 +110,13 @@ data Database
= All_Databases
| Empty
| OpenAlex
| PubMed
| PubMed (Maybe String)
| Arxiv
| HAL (Maybe Org)
| IsTex
| IsTex_Advanced
| Isidore
| EPO
| EPO (Maybe String) (Maybe String)
-- | News
-- | SocialNetworks
......@@ -133,13 +127,13 @@ derive instance Generic Database _
instance Show Database where
show All_Databases = "All Databases"
show OpenAlex = "OpenAlex"
show PubMed = "PubMed"
show (PubMed _) = "PubMed"
show Arxiv = "Arxiv"
show (HAL _) = "HAL"
show IsTex = "IsTex"
show IsTex_Advanced = "IsTex_Advanced"
show Isidore = "Isidore"
show EPO = "EPO"
show (EPO _ _) = "EPO"
show Empty = "Empty"
-- show News = "News"
......@@ -148,13 +142,13 @@ instance Show Database where
instance Doc Database where
doc All_Databases = "All databases"
doc OpenAlex = "OpenAlex db"
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"
doc IsTex_Advanced = "IsTex advanced search"
doc Isidore = "All (French) Social Sciences"
doc EPO = "European Patent Office"
doc (EPO _ _) = "European Patent Office"
doc Empty = "Empty"
-- doc News = "Web filtered by News"
......@@ -176,17 +170,24 @@ instance Doc Database where
derive instance Eq Database
instance JSON.WriteForeign Database where
writeImpl f = JSON.writeImpl $ show f
writeImpl (PubMed mAPIKey) = JSON.writeImpl { "db": "PubMed", "api_key": mAPIKey }
writeImpl (EPO mAPIUser mAPIToken) = JSON.writeImpl
{ "db": "PubMed"
, "api_user": mAPIUser
, "api_token": mAPIToken
}
writeImpl (HAL mOrg) = JSON.writeImpl { "db": "HAL", "org": mOrg }
writeImpl d = JSON.writeImpl { "db": show d }
allDatabases :: Array Database
allDatabases =
[ Empty
, PubMed
, PubMed Nothing
, HAL Nothing
, Arxiv
, OpenAlex
, IsTex
-- , EPO
-- , EPO Nothing Nothing
--, IsTex_Advanced
--, Isidore
--, Web
......@@ -197,25 +198,25 @@ allDatabases =
dbToInputValue :: Database -> String
dbToInputValue All_Databases = "all_databases"
dbToInputValue OpenAlex = "openalex"
dbToInputValue PubMed = "pubmed"
dbToInputValue (PubMed _) = "pubmed"
dbToInputValue Arxiv = "arxiv"
dbToInputValue (HAL _) = "hal"
dbToInputValue IsTex = "istex"
dbToInputValue IsTex_Advanced = "istex_advanced"
dbToInputValue Isidore = "isidore"
dbToInputValue EPO = "epo"
dbToInputValue (EPO _ _) = "epo"
dbToInputValue Empty = "empty"
dbFromInputValue :: String -> Maybe Database
dbFromInputValue "all_databases" = Just All_Databases
dbFromInputValue "openalex" = Just OpenAlex
dbFromInputValue "pubmed" = Just PubMed
dbFromInputValue "pubmed" = Just (PubMed 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 "epo" = Just EPO
dbFromInputValue "epo" = Just (EPO Nothing Nothing)
dbFromInputValue "empty" = Just Empty
dbFromInputValue _ = Nothing
......@@ -252,6 +253,9 @@ instance Read Org where
read _ = Nothing
derive instance Eq Org
-- | NOTE: IMT_org list isn't really used here in JSON
-- | encoding. Instead, for HAL, a special query is constructed in
-- | SearchField (queryHAL function).
instance JSON.WriteForeign Org where
writeImpl = JSON.writeImpl <<< show
......@@ -294,8 +298,7 @@ instance Show SearchOrder where
newtype SearchQuery = SearchQuery
{ query :: String
, databases :: Database
, datafield :: Maybe DataField
, datafield :: DataField
, files_id :: Array String
, lang :: Maybe Lang
, limit :: Maybe Int
......@@ -304,7 +307,6 @@ newtype SearchQuery = SearchQuery
, order :: Maybe SearchOrder
, epoAPIUser :: Maybe String
, epoAPIToken :: Maybe String
, pubmedAPIKey :: Maybe String
, selection :: ListSelection.Selection
}
......@@ -329,34 +331,29 @@ instance GT.ToQuery SearchQuery where
instance JSON.WriteForeign SearchQuery where
writeImpl
( SearchQuery
{ databases
, datafield
{ datafield
, lang
, node_id
, epoAPIUser
, epoAPIToken
, 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
, epoAPIUser
, epoAPIToken
, pubmedAPIKey
}
defaultSearchQuery :: SearchQuery
defaultSearchQuery = SearchQuery
{ query: ""
, databases: Empty
, datafield: Nothing
, datafield: External Empty
, files_id: []
, lang: Nothing
, limit: Nothing
......@@ -365,7 +362,6 @@ defaultSearchQuery = SearchQuery
, order: Nothing
, epoAPIUser: Nothing
, epoAPIToken: Nothing
, pubmedAPIKey: Nothing
, selection: ListSelection.NoList -- MyListsFirst
}
......
......@@ -68,8 +68,7 @@ asyncProgressCpt = R2.hereComponent here "asyncProgress" hCpt
here.log "[onProgress] TODO: Implement status killed"
if
GT.asyncTaskLogIsFinished atl ||
GT.asyncTaskLogIsError atl then do
GT.asyncTaskLogIsFinished atl then do
handleErrorInAsyncTaskLog errors atl
-- resetInterval intervalIdRef Nothing (pure unit)
onFinish unit
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment