[conduit] fixes to the searchAxv function to properly parse results

parent a2d78abe
......@@ -11,6 +11,3 @@ main = do
--let resC = searchAxv $ simpleQuery ["besov fluid"]
--runConduitRes $ resC .| outSnk
......@@ -27,7 +27,7 @@ type Limit = Int
type Soup = Tag String
batchSize :: Int
batchSize = 3000
batchSize = 400
------------------------------------------------------------
......@@ -102,13 +102,9 @@ searchAxv q =
let s = Ax.mkQuery q
in do rsp <- HT.httpBS =<< liftIO (parseRequest s)
case getResponseStatus rsp of
(Status 200 _) ->
let body = getResponseBody rsp
in
-- If no mo results, break, otherwise this keeps looping for next page forever
case Ax.getEntry (getSoup body) of
([], _) -> C.yieldMany []
_ -> getSoupC body >>= results q
(Status 200 _) -> case getSoup (getResponseBody rsp) of
[] -> C.yieldMany []
soups@(s:_) -> results q soups
st -> error $ "Error:" ++ show st
----------------------------------------------------------------------
......@@ -136,8 +132,9 @@ toSoup = C.awaitForever (C.yield . parseTags . B.unpack)
----------------------------------------------------------------------
results :: (Monad m, C.MonadIO m) =>
Ax.Query -> [Soup] -> C.ConduitT () Result m ()
results q sp = Ax.forEachEntryM sp (C.yield . mkResult)
>> searchAxv (Ax.nextPage q)
results q sp = do
Ax.forEachEntryM sp (C.yield . mkResult)
searchAxv (Ax.nextPage q)
----------------------------------------------------------------------
-- Get data and format
......@@ -182,4 +179,3 @@ mkResult sp = let abstract = Ax.getSummary sp & clean'
----------------------------------------------------------------------
outSnk :: (Monad m, C.MonadIO m) => C.ConduitT Result C.Void m ()
outSnk = C.awaitForever (liftIO . putStrLn . show)
......@@ -1070,4 +1070,3 @@ where
op = try (void (string "ANDNOT") >> return AndNot)
<|> try (void (string "OR") >> return Or)
<|> (void (string "AND") >> return And)
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