mirror of
https://github.com/philomena-dev/philomena.git
synced 2024-11-23 20:18:00 +01:00
feat: support limit param in reverse search
This commit is contained in:
parent
01fd397f93
commit
8f3f2c981b
3 changed files with 18 additions and 3 deletions
|
@ -25,7 +25,7 @@ defmodule Philomena.DuplicateReports do
|
|||
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
|
||||
dist = dist * 3
|
||||
|
||||
|
@ -39,7 +39,7 @@ defmodule Philomena.DuplicateReports do
|
|||
where:
|
||||
i.image_aspect_ratio >= ^(aspect_ratio - aspect_dist) and
|
||||
i.image_aspect_ratio <= ^(aspect_ratio + aspect_dist),
|
||||
limit: 10
|
||||
limit: ^limit
|
||||
end
|
||||
|
||||
@doc """
|
||||
|
|
|
@ -13,6 +13,7 @@ defmodule PhilomenaWeb.Api.Json.Search.ReverseController do
|
|||
images =
|
||||
image_params
|
||||
|> Map.put("distance", conn.params["distance"])
|
||||
|> Map.put("limit", conn.params["limit"])
|
||||
|> ImageReverse.images()
|
||||
|
||||
interactions = Interactions.user_interactions(images, user)
|
||||
|
|
|
@ -18,8 +18,9 @@ defmodule PhilomenaWeb.ImageReverse do
|
|||
{width, height} = analysis.dimensions
|
||||
aspect = width / height
|
||||
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]])
|
||||
|> Repo.all()
|
||||
end
|
||||
|
@ -60,4 +61,17 @@ defmodule PhilomenaWeb.ImageReverse do
|
|||
0.0
|
||||
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
|
||||
|
|
Loading…
Reference in a new issue