Implement search with PostgreSQL trigrams
Signed-off-by: Thomas Citharel <tcit@tcit.fr> Rename function to reflect that we only get one result Signed-off-by: Thomas Citharel <tcit@tcit.fr> Add loggers and make Ecto call parallels during search Signed-off-by: Thomas Citharel <tcit@tcit.fr> Implement trigrams for events & replace pg similarity operator % with <% Signed-off-by: Thomas Citharel <tcit@tcit.fr> Fix tests Signed-off-by: Thomas Citharel <tcit@tcit.fr>
This commit is contained in:
@@ -248,7 +248,19 @@ defmodule Mobilizon.Events do
|
||||
|
||||
query =
|
||||
from(e in Event,
|
||||
where: e.visibility == ^:public and ilike(e.title, ^like_sanitize(name)),
|
||||
where:
|
||||
e.visibility == ^:public and
|
||||
fragment(
|
||||
"f_unaccent(?) %> f_unaccent(?)",
|
||||
e.title,
|
||||
^name
|
||||
),
|
||||
order_by:
|
||||
fragment(
|
||||
"word_similarity(?, ?) desc",
|
||||
e.title,
|
||||
^name
|
||||
),
|
||||
preload: [:organizer_actor]
|
||||
)
|
||||
|> paginate(page, limit)
|
||||
@@ -256,11 +268,6 @@ defmodule Mobilizon.Events do
|
||||
Repo.all(query)
|
||||
end
|
||||
|
||||
# Sanitize the LIKE queries
|
||||
defp like_sanitize(value) do
|
||||
"%" <> String.replace(value, ~r/([\\%_])/, "\\1") <> "%"
|
||||
end
|
||||
|
||||
@doc """
|
||||
Creates a event.
|
||||
|
||||
|
||||
Reference in New Issue
Block a user