mirror of
https://github.com/philomena-dev/philomena.git
synced 2024-11-27 21:47:59 +01:00
Merge pull request #338 from philomena-dev/dr-sort
Order detected duplicates based on L2 distance from query point
This commit is contained in:
commit
d1f4eb960f
2 changed files with 19 additions and 0 deletions
|
@ -3,7 +3,9 @@ defmodule Philomena.DuplicateReports do
|
||||||
The DuplicateReports context.
|
The DuplicateReports context.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
import Philomena.DuplicateReports.Power
|
||||||
import Ecto.Query, warn: false
|
import Ecto.Query, warn: false
|
||||||
|
|
||||||
alias Ecto.Multi
|
alias Ecto.Multi
|
||||||
alias Philomena.Repo
|
alias Philomena.Repo
|
||||||
|
|
||||||
|
@ -46,6 +48,14 @@ 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),
|
||||||
|
order_by: [
|
||||||
|
asc:
|
||||||
|
power(it.nw - ^intensities.nw, 2) +
|
||||||
|
power(it.ne - ^intensities.ne, 2) +
|
||||||
|
power(it.sw - ^intensities.sw, 2) +
|
||||||
|
power(it.se - ^intensities.se, 2) +
|
||||||
|
power(i.image_aspect_ratio - ^aspect_ratio, 2)
|
||||||
|
],
|
||||||
limit: ^limit
|
limit: ^limit
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
9
lib/philomena/duplicate_reports/power.ex
Normal file
9
lib/philomena/duplicate_reports/power.ex
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
defmodule Philomena.DuplicateReports.Power do
|
||||||
|
@moduledoc false
|
||||||
|
|
||||||
|
defmacro power(left, right) do
|
||||||
|
quote do
|
||||||
|
fragment("power(?, ?)", unquote(left), unquote(right))
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
Loading…
Reference in a new issue