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:
@@ -2,7 +2,6 @@ defmodule MobilizonWeb.Resolvers.Event do
|
||||
@moduledoc """
|
||||
Handles the event-related GraphQL calls
|
||||
"""
|
||||
alias Mobilizon.Service.ActivityPub
|
||||
alias Mobilizon.Activity
|
||||
alias Mobilizon.Events.{Event, Participant}
|
||||
alias Mobilizon.Actors.User
|
||||
@@ -122,39 +121,6 @@ defmodule MobilizonWeb.Resolvers.Event do
|
||||
{:error, "You need to be logged-in to leave an event"}
|
||||
end
|
||||
|
||||
@doc """
|
||||
Search events by title
|
||||
"""
|
||||
def search_events(_parent, %{search: search, page: page, limit: limit}, _resolution) do
|
||||
{:ok, Mobilizon.Events.find_events_by_name(search, page, limit)}
|
||||
end
|
||||
|
||||
@doc """
|
||||
Search events and actors by title
|
||||
"""
|
||||
def search_events_and_actors(_parent, %{search: search, page: page, limit: limit}, _resolution) do
|
||||
search = String.trim(search)
|
||||
|
||||
found =
|
||||
case String.contains?(search, "@") do
|
||||
true ->
|
||||
with {:ok, actor} <- ActivityPub.find_or_make_actor_from_nickname(search) do
|
||||
actor
|
||||
else
|
||||
{:error, _err} ->
|
||||
nil
|
||||
end
|
||||
|
||||
_ ->
|
||||
Mobilizon.Events.find_events_by_name(search, page, limit) ++
|
||||
Mobilizon.Actors.find_actors_by_username_or_name(search, page, limit)
|
||||
end
|
||||
|
||||
require Logger
|
||||
Logger.debug(inspect(found))
|
||||
{:ok, found}
|
||||
end
|
||||
|
||||
@doc """
|
||||
Create an event
|
||||
"""
|
||||
|
||||
Reference in New Issue
Block a user