Merge pull request from MareStare/fix/add-sorting-to-server-side-autocomplete

Add client-side sorting to server-side autocomplete to work around data desync bugs
This commit is contained in:
liamwhite 2025-03-26 22:04:50 -04:00 committed by GitHub
commit 78550a6322
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -81,6 +81,10 @@ defmodule PhilomenaWeb.Autocomplete.TagController do
}
)
|> Enum.filter(&(&1.images > 0))
# Sometimes we have data desynchronization between OpenSearch and Postgres due
# to bugs. This client-side sort serves as a patch to make sure we have correct
# ranking of the autocomplete results even in the case of desynchronization.
|> Enum.sort_by(& &1.images, :desc)
|> Enum.take(limit)
end