diff --git a/src/Monocle/Backend/Index.hs b/src/Monocle/Backend/Index.hs index fbbdc15b9..238c3ccd8 100644 --- a/src/Monocle/Backend/Index.hs +++ b/src/Monocle/Backend/Index.hs @@ -298,7 +298,7 @@ upgradeConfigV1 = do let entity = CrawlerPB.EntityTypeENTITY_TYPE_PROJECT search = BH.mkSearch (Just $ crawlerMDQuery entity crawlerName) Nothing index <- getIndexName - resp <- fmap BH.hitSource <$> Q.simpleSearchLegacy index search + resp <- fmap BH.hitSource <$> esSearchByIndex index search pure $ catMaybes resp isCrawlerLastCommitAtIsDefault :: Config.Index -> ECrawlerMetadata -> Bool isCrawlerLastCommitAtIsDefault @@ -921,7 +921,7 @@ crawlerMDQuery entity crawlerName = getLastUpdated :: MonoQuery :> es => IndexEffects es => Config.Crawler -> CrawlerPB.EntityType -> Word32 -> Eff es (Maybe ECrawlerMetadataObject) getLastUpdated crawler entity offset = do index <- getIndexName - resp <- fmap BH.hitSource <$> Q.simpleSearchLegacy index search + resp <- fmap BH.hitSource <$> esSearchByIndex index search case nonEmpty (catMaybes resp) of Nothing -> pure Nothing Just xs -> diff --git a/src/Monocle/Backend/Queries.hs b/src/Monocle/Backend/Queries.hs index 7497f5254..4541925bc 100644 --- a/src/Monocle/Backend/Queries.hs +++ b/src/Monocle/Backend/Queries.hs @@ -29,10 +29,6 @@ import Streaming.Prelude qualified as Streaming import Monocle.Effects import Proto3.Suite (Enumerated (Enumerated)) --- Legacy wrappers -simpleSearchLegacy :: (LoggerEffect :> es, Error ElasticError :> es, ElasticEffect :> es, FromJSON a) => BH.IndexName -> BH.Search -> Eff es [BH.Hit a] -simpleSearchLegacy indexName search = BH.hits . BH.searchHits <$> esSearchLegacy indexName search - ------------------------------------------------------------------------------- -- Low level wrappers for bloodhound. {- TODO: migrate to proper effect diff --git a/src/Monocle/Effects.hs b/src/Monocle/Effects.hs index 201be592f..f0ca4bb05 100644 --- a/src/Monocle/Effects.hs +++ b/src/Monocle/Effects.hs @@ -436,6 +436,10 @@ esSearch :: (Error ElasticError :> es, ElasticEffect :> es, ToJSON body, FromJSO esSearch iname body scrollReq = do runBHIOSafe "esSearch" body $ BHR.search iname body scrollReq +-- | This is similar to esScanSearch, but 'searchByIndex' respects search size and sort order +esSearchByIndex :: (Error ElasticError :> es, ElasticEffect :> es, ToJSON body, FromJSONField resp) => BH.IndexName -> body -> Eff es [BH.Hit resp] +esSearchByIndex iname body = BH.hits . BH.searchHits <$> esSearch iname body BHR.NoScroll + esAdvance :: (Error ElasticError :> es, ElasticEffect :> es, FromJSON resp) => BH.ScrollId -> Eff es (BH.SearchResult resp) esAdvance scroll = do runBHIOSafe "esAdvance" scroll $ BHR.advance scroll @@ -502,24 +506,7 @@ esUpdateDocument :: (Error ElasticError :> es, ElasticEffect :> es) => ToJSON a esUpdateDocument iname ids body doc = do runBHIOSafe "esUpdateDocument" body $ BH.updateDocument iname ids body doc --- Legacy wrappers -esSearchLegacy :: (LoggerEffect :> es, Error ElasticError :> es, ElasticEffect :> es, FromJSON a) => BH.IndexName -> BH.Search -> Eff es (BH.SearchResult a) -esSearchLegacy indexName search = do - (rawResp, resp) <- runBHIOSafe "esSearchLegacy" search do - -- logText . decodeUtf8 . encode $ search - rawResp <- BH.searchByIndex indexName search - -- logText $ show rawResp - (\resp -> (rawResp, resp)) <$> BH.parseEsResponse rawResp - case resp of - Left e -> handleError e rawResp - Right x -> pure x - where - handleError resp rawResp = do - logWarn "Elastic response failed" ["status" .= BH.errorStatus resp, "message" .= BH.errorMessage resp] - error $ "Elastic response failed: " <> show rawResp - ------------------------------------------------------------------ --- -- | HTTP Effect