Commit 4fbe4915 authored by Przemyslaw Kaminski's avatar Przemyslaw Kaminski

[HAL] add simple year implementation to HAL search

parent 07b5ffa8
...@@ -40,6 +40,7 @@ defaultSearch = { databases: Empty ...@@ -40,6 +40,7 @@ defaultSearch = { databases: Empty
, lang : Nothing , lang : Nothing
, term : "" , term : ""
, url : "" , url : ""
, year : ""
} }
type Props = type Props =
...@@ -77,6 +78,18 @@ searchFieldCpt = here.component "searchField" cpt ...@@ -77,6 +78,18 @@ searchFieldCpt = here.component "searchField" cpt
type ComponentProps = type ComponentProps =
( search :: T.Box Search ) ( search :: T.Box Search )
componentYear :: R2.Component ComponentProps
componentYear = R.createElement componentYearCpt
componentYearCpt :: R.Component ComponentProps
componentYearCpt = here.component "componentYear" cpt where
cpt { search } _ = do
pure $ H.div {}
[ H.input { on: { blur: modify
, change: modify
, input: modify } } ]
where
modify e = T.modify_ (_ { year = R.unsafeEventValue e }) search
type ComponentIMTProps = type ComponentIMTProps =
( session :: Session ( session :: Session
| ComponentProps ) | ComponentProps )
...@@ -405,6 +418,10 @@ datafieldInputCpt = here.component "datafieldInput" cpt where ...@@ -405,6 +418,10 @@ datafieldInputCpt = here.component "datafieldInput" cpt where
then componentIMT { search, session } [] then componentIMT { search, session } []
else H.div {} [] else H.div {} []
, if isHAL search'.datafield
then componentYear { search } []
else H.div {} []
, if isCNRS search'.datafield , if isCNRS search'.datafield
then componentCNRS { search } [] then componentCNRS { search } []
else H.div {} [] else H.div {} []
...@@ -510,17 +527,18 @@ triggerSearch { onSearch, errors, session, selection, search } = ...@@ -510,17 +527,18 @@ triggerSearch { onSearch, errors, session, selection, search } =
launchAff_ $ do launchAff_ $ do
liftEffect $ do liftEffect $ do
let here' = "[triggerSearch] Searching " let here' = "[triggerSearch] Searching "
log2 (here' <> "databases: ") (show search.databases) here.log2 (here' <> "databases: ") (show search.databases)
log2 (here' <> "datafield: ") (show search.datafield) here.log2 (here' <> "datafield: ") (show search.datafield)
log2 (here' <> "term: ") search.term here.log2 (here' <> "term: ") search.term
log2 (here' <> "lang: ") (show search.lang) here.log2 (here' <> "lang: ") (show search.lang)
case search.node_id of case search.node_id of
Nothing -> liftEffect $ log "[triggerSearch] node_id is Nothing, don't know what to do" Nothing -> liftEffect $ here.log "[triggerSearch] node_id is Nothing, don't know what to do"
Just id -> do Just id -> do
liftEffect $ here.log2 "[triggerSearch] search" search
eTask <- performSearch session id $ searchQuery selection search eTask <- performSearch session id $ searchQuery selection search
handleRESTError errors eTask $ \task -> liftEffect $ do handleRESTError errors eTask $ \task -> liftEffect $ do
log2 "[triggerSearch] task" task here.log2 "[triggerSearch] task" task
onSearch task onSearch task
--liftEffect $ do --liftEffect $ do
...@@ -531,22 +549,53 @@ searchQuery :: ListSelection.Selection -> Search -> SearchQuery ...@@ -531,22 +549,53 @@ searchQuery :: ListSelection.Selection -> Search -> SearchQuery
searchQuery selection { datafield: Nothing, term } = searchQuery selection { datafield: Nothing, term } =
over SearchQuery (_ { query = term over SearchQuery (_ { query = term
, selection = selection }) defaultSearchQuery , selection = selection }) defaultSearchQuery
searchQuery selection { databases, datafield: datafield@(Just (External (Just (HAL (Just (IMT imtOrgs)))))), lang, term, node_id } = -- TODO Simplify both HAL Nothing and HAL (Just IMT) cases
searchQuery selection { databases
, datafield: datafield@(Just (External (Just (HAL Nothing))))
, lang
, term
, node_id
, year } =
over SearchQuery (_ { databases = databases
, datafield = datafield
, lang = lang
, node_id = node_id
, query = query
, selection = selection
}) defaultSearchQuery
where
query = "(en_title_t:\"" <> termEscaped <> "\" OR en_abstract_t:\"" <> termEscaped <> "\")" <> yearQuery
-- TODO: Escape double quotes
termEscaped = term
yearQuery = if year == "" then
""
else
" AND producedDateY_i:" <> year
searchQuery selection { databases
, datafield: datafield@(Just (External (Just (HAL (Just (IMT imtOrgs))))))
, lang
, term
, node_id
, year } =
over SearchQuery (_ { databases = databases over SearchQuery (_ { databases = databases
, datafield = datafield , datafield = datafield
, lang = lang , lang = lang
, node_id = node_id , node_id = node_id
, query = term' , query = query
, selection = selection , selection = selection
}) defaultSearchQuery }) defaultSearchQuery
where where
term' = "(en_title_t:\"" <> termEscaped <> "\" OR en_abstract_t:\"" <> termEscaped <> "\")" <> structQuery query = "(en_title_t:\"" <> termEscaped <> "\" OR en_abstract_t:\"" <> termEscaped <> "\")" <> structQuery <> yearQuery
-- TODO: Escape double quotes -- TODO: Escape double quotes
termEscaped = term termEscaped = term
structQuery = if Set.isEmpty imtOrgs then structQuery = if Set.isEmpty imtOrgs then
"" ""
else else
" AND (" <> structIds <> ")" " AND (" <> structIds <> ")"
yearQuery = if year == "" then
""
else
" AND producedDateY_i:" <> year
joinFunc :: IMT_org -> String joinFunc :: IMT_org -> String
joinFunc All_IMT = "" joinFunc All_IMT = ""
joinFunc (IMT_org { school_id }) = "structId_i:" <> school_id joinFunc (IMT_org { school_id }) = "structId_i:" <> school_id
......
...@@ -29,6 +29,7 @@ type Search = { databases :: Database ...@@ -29,6 +29,7 @@ type Search = { databases :: Database
, lang :: Maybe Lang , lang :: Maybe Lang
, node_id :: Maybe Int , node_id :: Maybe Int
, term :: String , term :: String
, year :: String -- TODO Array Int
} }
isIsTex_Advanced :: Maybe DataField -> Boolean isIsTex_Advanced :: Maybe DataField -> Boolean
......
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