From 7a73578d7cdc47e77f5e066ba2e593decc4900ce Mon Sep 17 00:00:00 2001 From: Rok Garbas Date: Mon, 15 Jun 2020 09:51:09 +0200 Subject: [PATCH] handle 10000 package limit in the UI correctly (#99) fixes #94 Co-authored-by: Samuel Dionne-Riel --- src/Page/Options.elm | 2 +- src/Page/Packages.elm | 3 +-- src/Search.elm | 24 +++++++++++++++++++----- 3 files changed, 21 insertions(+), 8 deletions(-) diff --git a/src/Page/Options.elm b/src/Page/Options.elm index 02005b0..dca2809 100644 --- a/src/Page/Options.elm +++ b/src/Page/Options.elm @@ -392,7 +392,7 @@ makeRequest : -> Cmd Msg makeRequest options channel query from size = Search.makeRequest - (makeRequestBody query from size) + makeRequestBody ("latest-" ++ String.fromInt options.mappingSchemaVersion ++ "-" ++ channel) decodeResultItemSource options diff --git a/src/Page/Packages.elm b/src/Page/Packages.elm index fbdc5fd..0d1de25 100644 --- a/src/Page/Packages.elm +++ b/src/Page/Packages.elm @@ -476,7 +476,7 @@ makeRequest : -> Cmd Msg makeRequest options channel query from size = Search.makeRequest - (makeRequestBody query from size) + makeRequestBody ("latest-" ++ String.fromInt options.mappingSchemaVersion ++ "-" ++ channel) decodeResultItemSource options @@ -540,4 +540,3 @@ decodeResultPackageHydraPath = Json.Decode.map2 ResultPackageHydraPath (Json.Decode.field "output" Json.Decode.string) (Json.Decode.field "path" Json.Decode.string) - diff --git a/src/Search.elm b/src/Search.elm index 22e28c9..4fa6c7a 100644 --- a/src/Search.elm +++ b/src/Search.elm @@ -402,8 +402,13 @@ view path title model viewSuccess outMsg = model.from + model.size ) ++ " of " - ++ String.fromInt result.hits.total.value - ++ "." + ++ (if result.hits.total.value == 10000 then + "more than 10000 results, please provide more precise search terms." + + else + String.fromInt result.hits.total.value + ++ "." + ) ) ] ] @@ -554,7 +559,7 @@ type alias Options = makeRequest : - Http.Body + (String -> Int -> Int -> Http.Body) -> String -> Json.Decode.Decoder a -> Options @@ -562,14 +567,23 @@ makeRequest : -> Int -> Int -> Cmd (Msg a) -makeRequest body index decodeResultItemSource options query from size = +makeRequest makeRequestBody index decodeResultItemSource options query from sizeRaw = + let + -- you can not request more then 10000 results otherwise it will return 404 + size = + if from + sizeRaw > 10000 then + 10000 - from + + else + sizeRaw + in Http.riskyRequest { method = "POST" , headers = [ Http.header "Authorization" ("Basic " ++ Base64.encode (options.username ++ ":" ++ options.password)) ] , url = options.url ++ "/" ++ index ++ "/_search" - , body = body + , body = makeRequestBody query from size , expect = Http.expectJson (RemoteData.fromResult >> QueryResponse)