mirror of
https://github.com/philomena-dev/philomena.git
synced 2024-11-23 20:18:00 +01:00
Merge pull request #332 from mdashlw/reverse-limit
feat: support limit param in reverse search
This commit is contained in:
commit
11b414bf7b
3 changed files with 18 additions and 3 deletions
|
@ -25,7 +25,7 @@ defmodule Philomena.DuplicateReports do
|
||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
|
|
||||||
def duplicates_of(intensities, aspect_ratio, dist \\ 0.25, aspect_dist \\ 0.05) do
|
def duplicates_of(intensities, aspect_ratio, dist \\ 0.25, aspect_dist \\ 0.05, limit \\ 10) do
|
||||||
# for each color channel
|
# for each color channel
|
||||||
dist = dist * 3
|
dist = dist * 3
|
||||||
|
|
||||||
|
@ -39,7 +39,7 @@ defmodule Philomena.DuplicateReports do
|
||||||
where:
|
where:
|
||||||
i.image_aspect_ratio >= ^(aspect_ratio - aspect_dist) and
|
i.image_aspect_ratio >= ^(aspect_ratio - aspect_dist) and
|
||||||
i.image_aspect_ratio <= ^(aspect_ratio + aspect_dist),
|
i.image_aspect_ratio <= ^(aspect_ratio + aspect_dist),
|
||||||
limit: 10
|
limit: ^limit
|
||||||
end
|
end
|
||||||
|
|
||||||
@doc """
|
@doc """
|
||||||
|
|
|
@ -13,6 +13,7 @@ defmodule PhilomenaWeb.Api.Json.Search.ReverseController do
|
||||||
images =
|
images =
|
||||||
image_params
|
image_params
|
||||||
|> Map.put("distance", conn.params["distance"])
|
|> Map.put("distance", conn.params["distance"])
|
||||||
|
|> Map.put("limit", conn.params["limit"])
|
||||||
|> ImageReverse.images()
|
|> ImageReverse.images()
|
||||||
|
|
||||||
interactions = Interactions.user_interactions(images, user)
|
interactions = Interactions.user_interactions(images, user)
|
||||||
|
|
|
@ -18,8 +18,9 @@ defmodule PhilomenaWeb.ImageReverse do
|
||||||
{width, height} = analysis.dimensions
|
{width, height} = analysis.dimensions
|
||||||
aspect = width / height
|
aspect = width / height
|
||||||
dist = normalize_dist(image_params)
|
dist = normalize_dist(image_params)
|
||||||
|
limit = parse_limit(image_params)
|
||||||
|
|
||||||
DuplicateReports.duplicates_of(intensities, aspect, dist, dist)
|
DuplicateReports.duplicates_of(intensities, aspect, dist, dist, limit)
|
||||||
|> preload([:user, :intensity, [:sources, tags: :aliases]])
|
|> preload([:user, :intensity, [:sources, tags: :aliases]])
|
||||||
|> Repo.all()
|
|> Repo.all()
|
||||||
end
|
end
|
||||||
|
@ -60,4 +61,17 @@ defmodule PhilomenaWeb.ImageReverse do
|
||||||
0.0
|
0.0
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
defp parse_limit(%{"limit" => limit}) do
|
||||||
|
limit
|
||||||
|
|> Integer.parse()
|
||||||
|
|> case do
|
||||||
|
{limit, _rest} -> limit
|
||||||
|
_ -> 10
|
||||||
|
end
|
||||||
|
|> max(1)
|
||||||
|
|> min(50)
|
||||||
|
end
|
||||||
|
|
||||||
|
defp parse_limit(_), do: 10
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue