handle 10000 package limit in the UI correctly (#99)

fixes #94

Co-authored-by: Samuel Dionne-Riel <samuel@dionne-riel.com>
This commit is contained in:
Rok Garbas 2020-06-15 09:51:09 +02:00 committed by GitHub
parent a8b7faa398
commit 7a73578d7c
Failed to generate hash of commit
3 changed files with 21 additions and 8 deletions

View file

@ -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

View file

@ -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)

View file

@ -402,9 +402,14 @@ 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
++ "."
)
)
]
]
, viewPager outMsg model result path
@ -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)