Use decimal parsing for search dist value

This commit is contained in:
Liam 2024-06-02 22:48:24 -04:00
parent 5729cac98b
commit 410332003b

View file

@ -44,10 +44,20 @@ defmodule PhilomenaWeb.ImageReverse do
# because this is more efficient to index. # because this is more efficient to index.
defp normalize_dist(%{"distance" => distance}) do defp normalize_dist(%{"distance" => distance}) do
distance distance
|> String.to_float() |> parse_dist()
|> max(0.01) |> max(0.01)
|> min(1.0) |> min(1.0)
end end
defp normalize_dist(_dist), do: 0.25 defp normalize_dist(_dist), do: 0.25
defp parse_dist(dist) do
case Decimal.parse(dist) do
{value, _rest} ->
Decimal.to_float(value)
_ ->
0.0
end
end
end end