Commit 664bec88 authored by Yoelis Acourt's avatar Yoelis Acourt

feat: add filter options to openalex query

parent a2747b50
......@@ -2,6 +2,7 @@ module Gargantext.Components.Forest.Tree.Node.Action.Search.SearchForm where
import Gargantext.Prelude
import Affjax.RequestHeader (value)
import Data.Array as A
import Data.Maybe (Maybe(..), maybe, fromMaybe)
import Data.Newtype (over)
......@@ -12,6 +13,7 @@ import Data.Tuple (Tuple(..))
import Effect (Effect)
import Effect.Aff (launchAff_)
import Effect.Class (liftEffect)
import Gargantext.Components.Bootstrap (formInput)
import Gargantext.Components.Forest.Tree.Node.Action.Search.Frame (searchIframes)
import Gargantext.Components.Forest.Tree.Node.Action.Search.Types (DataField(..), Database(..), IMT_org(..), Org(..), SearchQuery(..), allOrgs, dataFields, defaultSearchQuery, doc, performSearch, datafield2database, Search, dbFromInputValue, dbToInputValue)
import Gargantext.Components.GraphQL.Endpoints (getIMTSchools, getUser)
......@@ -38,6 +40,7 @@ defaultSearch =
{ databases: Empty
, datafield: Just (External Empty)
, node_id: Nothing
, filters: ""
, epoApiUser: Nothing
, epoApiToken: Nothing
, pubmedApiKey: Nothing
......@@ -594,9 +597,9 @@ datafieldInputCpt = here.component "datafieldInput" cpt
Just (External (HAL (Just (IMT _)))) -> componentIMT { search, session } [ langNav { langs, search } [] ]
Just (External (HAL (Just (CNRS _)))) -> componentCNRS { search } [ langNav { langs, search } [] ]
Just (External (HAL _)) -> orgInput { orgs: allOrgs, search } [ langNav { langs, search } [] ]
Just (External OpenAlex) -> H.div {} [ H.text "Optional filters" ]
Just (External OpenAlex) -> filtersInput { search } []
Just Web -> langNav { langs, search } []
_ -> empty -- Default for unsupported or missing fields
_ -> empty
pure $ H.div {}
[ dataFieldNav { search } []
......@@ -609,6 +612,48 @@ type SearchInputProps =
( search :: T.Box Search
)
filtersExplanation :: R.Element
filtersExplanation = H.div { className: "container mt-5" }
[ H.div { className: "alert alert-info" }
[ H.text "To apply multiple filters in OpenAlex, separate each condition with commas. For example, to find works authored by \"John Doe\" from \"Harvard University\" published in 2023, the query would be structured as:" ]
, H.pre { className: "bg-light-2" }
[ H.code {}
[ H.text "authorships.author.id%3Aa5109346276,authorships.institutions.lineage%3Ai57206974"
]
]
, H.text "This syntax allows you to combine multiple filters as an "
, H.strong {} [ H.text "AND" ]
, H.text " query, ensuring all conditions are met in the results."
]
filtersInput :: R2.Component SearchInputProps
filtersInput = R.createElement filtersInputCpt
filtersInputCpt :: R.Component SearchInputProps
filtersInputCpt =
let
cpt { search } _ = do
state <- T.useLive T.unequal search
pure $ H.div { className: "form-group px-1" }
[ H.label { className: "form-group__label", htmlFor: "filters-openalex-input" }
[ filtersExplanation
]
, H.input
{ id: "filters-openalex-input"
, value: state.filters
, className: "form-control"
, on: { change: (\e -> T.modify_ (_ { filters = e.target.value }) search) }
, placeholder: "Add filters"
, type: "text"
}
]
in
here.component "filtersInput" cpt
-- Je veux un composant input qui apparait quand on click sur le datasource openalex
-- quand un texte est entré je veux qu'il soit enregistré dans
searchInput :: R2.Component SearchInputProps
searchInput = R.createElement searchInputCpt
......@@ -633,15 +678,6 @@ searchInputCpt = here.component "searchInput" cpt
}
]
-- pure $
-- H.div { className : "" }
-- [ H.input { className: "form-control"
-- , defaultValue: search.term
-- , on: { input : onInput valueRef setSearch }
-- , placeholder: "Your Query here"
-- , type: "text"
-- }
-- ]
onBlur valueRef search value = do
R.setRef valueRef value
T.modify_ (_ { term = value }) search
......@@ -822,6 +858,19 @@ searchQuery
}
)
defaultSearchQuery
searchQuery selection { databases, filters, datafield: datafield@(Just (External OpenAlex)), lang, term, node_id } =
over SearchQuery
( _
{ databases = databases
, datafield = datafield
, filters = filters
, lang = lang
, node_id = node_id
, query = term
, selection = selection
}
)
defaultSearchQuery
searchQuery selection { databases, datafield, lang, term, node_id } =
over SearchQuery
( _
......
......@@ -29,6 +29,7 @@ type Search =
{ databases :: Database
, datafield :: Maybe DataField
, url :: String
, filters :: String
, lang :: Maybe Lang
, node_id :: Maybe Int
, epoApiUser :: Maybe String
......@@ -298,6 +299,7 @@ newtype SearchQuery = SearchQuery
, datafield :: Maybe DataField
, files_id :: Array String
, lang :: Maybe Lang
, filters :: String
, limit :: Maybe Int
, node_id :: Maybe Int
, offset :: Maybe Int
......@@ -337,6 +339,7 @@ instance JSON.WriteForeign SearchQuery where
, epoAPIToken
, pubmedAPIKey
, query
, filters
, selection
}
) =
......@@ -348,6 +351,7 @@ instance JSON.WriteForeign SearchQuery where
, node_id: fromMaybe 0 node_id
, flowListWith: selection
, epoAPIUser
, filters: filters
, epoAPIToken
, pubmedAPIKey
}
......@@ -360,6 +364,7 @@ defaultSearchQuery = SearchQuery
, files_id: []
, lang: Nothing
, limit: Nothing
, filters: ""
, node_id: Nothing
, offset: Nothing
, order: Nothing
......
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