Commit a8799bb2 authored by Mudada's avatar Mudada

Add 'generateRequestByStructID' to make request filtered by structId

parent 802033bd
......@@ -9,11 +9,34 @@ import Servant.Client
import HAL (getMetadataWith)
import HAL.Client
import HAL.Doc
import HAL
import Tree
import qualified Data.Text as T
imt :: [T.Text]
imt = [
"224096"
,"144103"
,"84538"
,"300104"
,"300362"
,"301262"
,"301442"
,"301492"
,"302102"
,"421532"
,"497330"
,"352124"
,"481355"
,"469216"
,"542824"
,"6279"
,"29212"
]
main :: IO ()
main = do
res <- getMetadataWith "artificial intelligence" (Just 10)
res <- getMetadataWith (generateRequestByStructID "artificial intelligence" imt) (Just 10)
case res of
(Left err) -> print err
(Right val) -> print $ _docs val
......@@ -41,3 +41,16 @@ runStructureRequest rq =
runSearchRequest :: [Text] -> IO (Either ClientError (Response Corpus))
runSearchRequest rq =
runHalAPIClient $ search (Just requestedFields) rq Nothing Nothing Nothing
generateRequestByStructID :: Text -> [Text] -> Text
generateRequestByStructID rq struct_ids =
"text:" <>
rq
<> " AND "
<> "structId_i:("
<> (flattenPipe struct_ids)
<> ")"
flattenPipe :: [Text] -> Text
flattenPipe (x:[]) = x
flattenPipe (x:xs) = x <> " || " <> flattenPipe xs
......@@ -22,12 +22,13 @@ data Corpus = Corpus
_corpus_date :: Maybe Text,
_corpus_source :: Maybe Text,
_corpus_authors_names :: [Text],
_corpus_authors_affiliations :: [Text]
_corpus_authors_affiliations :: [Text],
_corpus_struct_id :: [Int]
} deriving (Show, Generic)
L.makeLenses ''Corpus
instance Default Corpus where
def = Corpus def def def def def def def
def = Corpus def def def def def def def def
instance FromJSON Corpus where
parseJSON (Object o) = Corpus <$>
......@@ -38,6 +39,7 @@ instance FromJSON Corpus where
<*> (o .:? "source_s")
<*> (o .: "authFullName_s" <|> return [])
<*> (o .: "authOrganism_s" <|> return [])
<*> (o .: "structId_i" <|> return [])
instance ToHttpApiData Corpus where
toUrlPiece _ = "docid,title_s,abstract_s,submittedDate_s,source_s,authFullName_s,authOrganism_s"
toUrlPiece _ = "docid,title_s,abstract_s,submittedDate_s,source_s,authFullName_s,authOrganism_s,structId_i"
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