Commit 8688d3c1 authored by Przemyslaw Kaminski's avatar Przemyslaw Kaminski

[HAL] refactor search query for hal

parent 55b2a8c9
Pipeline #2642 failed with stage
in 0 seconds
......@@ -560,17 +560,9 @@ searchQuery selection { databases
, datafield = datafield
, lang = lang
, node_id = node_id
, query = query
, query = queryHAL term Nothing year
, 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
......@@ -581,17 +573,30 @@ searchQuery selection { databases
, datafield = datafield
, lang = lang
, node_id = node_id
, query = query
, query = queryHAL term (Just imtOrgs) year
, selection = selection
}) defaultSearchQuery
searchQuery selection { databases, datafield, lang, term, node_id } =
over SearchQuery (_ { databases = databases
, datafield = datafield
, lang = lang
, node_id = node_id
, query = term
, selection = selection
}) defaultSearchQuery
queryHAL :: String -> Maybe (Set.Set IMT_org) -> String -> String
queryHAL term mIMTOrgs year =
"(en_title_t:\"" <> termEscaped <> "\" OR en_abstract_t:\"" <> termEscaped <> "\")" <> structQuery <> yearQuery
where
query = "(en_title_t:\"" <> termEscaped <> "\" OR en_abstract_t:\"" <> termEscaped <> "\")" <> structQuery <> yearQuery
-- TODO: Escape double quotes
termEscaped = term
structQuery = if Set.isEmpty imtOrgs then
structQuery = case mIMTOrgs of
Nothing -> ""
Just imtOrgs -> if Set.isEmpty imtOrgs then
""
else
" AND (" <> structIds <> ")"
" AND (" <> (structIds imtOrgs) <> ")"
yearQuery = if year == "" then
""
else
......@@ -599,14 +604,5 @@ searchQuery selection { databases
joinFunc :: IMT_org -> String
joinFunc All_IMT = ""
joinFunc (IMT_org { school_id }) = "structId_i:" <> school_id
structIds :: String
structIds = joinWith " OR " $ joinFunc <$> Set.toUnfoldable imtOrgs
searchQuery selection { databases, datafield, lang, term, node_id } =
over SearchQuery (_ { databases = databases
, datafield = datafield
, lang = lang
, node_id = node_id
, query = term
, selection = selection
}) defaultSearchQuery
structIds :: Set.Set IMT_org -> String
structIds imtOrgs = joinWith " OR " $ joinFunc <$> Set.toUnfoldable imtOrgs
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