mirror of
https://github.com/philomena-dev/philomena.git
synced 2024-11-27 13:47:58 +01:00
Use decimal parsing for search dist value
This commit is contained in:
parent
5729cac98b
commit
410332003b
1 changed files with 11 additions and 1 deletions
|
@ -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
|
||||||
|
|
Loading…
Reference in a new issue