Improve search

Signed-off-by: Thomas Citharel <tcit@tcit.fr>
This commit is contained in:
Thomas Citharel
2022-08-22 12:12:09 +02:00
parent 444e0d6a0c
commit baac00f678
36 changed files with 1343 additions and 1013 deletions

View File

@@ -12,7 +12,7 @@ defmodule Mobilizon.GraphQL.Resolvers.Config do
"""
@spec get_config(any(), map(), Absinthe.Resolution.t()) :: {:ok, map()}
def get_config(_parent, _params, %{context: %{ip: ip}}) do
# ip = "2a01:e0a:184:2000:1112:e19d:9779:88c8"
ip = "2a01:e0a:184:2000:1112:e19d:9779:88c8"
geolix = Geolix.lookup(ip)
country_code =

View File

@@ -95,6 +95,14 @@ defmodule Mobilizon.GraphQL.Schema.SearchType do
arg(:type, :event_type, description: "Whether the event is online or in person")
arg(:category, :string, description: "The category for the event")
arg(:category_one_of, list_of(:string),
description: "The list of categories the event can be in"
)
arg(:status_one_of, list_of(:event_status),
description: "The list of statuses this event can have"
)
arg(:radius, :float,
default_value: 50,
description: "Radius around the location to search in"

View File

@@ -530,6 +530,8 @@ defmodule Mobilizon.Events do
|> events_for_begins_on(args)
|> events_for_ends_on(args)
|> events_for_category(args)
|> events_for_categories(args)
|> events_for_statuses(args)
|> events_for_tags(args)
|> events_for_location(args)
|> filter_online(args)
@@ -1320,6 +1322,19 @@ defmodule Mobilizon.Events do
defp events_for_category(query, _args), do: query
@spec events_for_categories(Ecto.Queryable.t(), map()) :: Ecto.Query.t()
defp events_for_categories(query, %{category_one_of: category_one_of}) when length(category_one_of) > 0 do
where(query, [q], q.category in ^category_one_of)
end
defp events_for_categories(query, _args), do: query
defp events_for_statuses(query, %{status_one_of: status_one_of}) when length(status_one_of) > 0 do
where(query, [q], q.status in ^status_one_of)
end
defp events_for_statuses(query, _args), do: query
@spec events_for_tags(Ecto.Queryable.t(), map()) :: Ecto.Query.t()
defp events_for_tags(query, %{tags: tags}) when is_valid_string(tags) do
query