From 08c5d997dc033abcc3053b56ffddeb0d161b5d0c Mon Sep 17 00:00:00 2001 From: Rok Garbas Date: Wed, 8 Jul 2020 17:05:57 +0200 Subject: [PATCH] include query item in search suggestions (#117) but only if it does not end with ".", since items with "." are partial names only used to drill down to the actual package/option name. when there is one result in suggestions and is the same as query we don't show results --- src/Search.elm | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/src/Search.elm b/src/Search.elm index fbdf8d4..ec4fe44 100644 --- a/src/Search.elm +++ b/src/Search.elm @@ -641,10 +641,30 @@ getSuggestions query querySuggest = in case querySuggest of RemoteData.Success result -> - result.suggest - |> maybeList (\x -> x.query |> maybeList (List.map .options)) - |> List.concat - |> List.filter (\x -> x.text /= query) + let + suggestions = + result.suggest + |> maybeList (\x -> x.query |> maybeList (List.map .options)) + |> List.concat + |> List.filter + (\x -> + if String.endsWith "." (Maybe.withDefault "" query) then + x.text /= query + + else + True + ) + + firstItemText items = + items + |> List.head + |> Maybe.andThen .text + in + if List.length suggestions == 1 && firstItemText suggestions == query then + [] + + else + suggestions _ -> []