From 410332003b34cd25910ff66fdc970cdef99e1bcd Mon Sep 17 00:00:00 2001 From: Liam Date: Sun, 2 Jun 2024 22:48:24 -0400 Subject: [PATCH] Use decimal parsing for search dist value --- lib/philomena_web/image_reverse.ex | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/lib/philomena_web/image_reverse.ex b/lib/philomena_web/image_reverse.ex index e1d78a50..4fa5f459 100644 --- a/lib/philomena_web/image_reverse.ex +++ b/lib/philomena_web/image_reverse.ex @@ -44,10 +44,20 @@ defmodule PhilomenaWeb.ImageReverse do # because this is more efficient to index. defp normalize_dist(%{"distance" => distance}) do distance - |> String.to_float() + |> parse_dist() |> max(0.01) |> min(1.0) end 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