2020-01-26 20:34:25 +01:00
|
|
|
defmodule Mobilizon.GraphQL.Schema.SearchType do
|
2019-04-12 15:04:32 +02:00
|
|
|
@moduledoc """
|
|
|
|
Schema representation for Search
|
|
|
|
"""
|
|
|
|
use Absinthe.Schema.Notation
|
|
|
|
|
2020-11-06 11:34:32 +01:00
|
|
|
alias Mobilizon.Actors.Actor
|
|
|
|
alias Mobilizon.Events.Event
|
2020-01-26 20:34:25 +01:00
|
|
|
alias Mobilizon.GraphQL.Resolvers.Search
|
2022-08-26 16:08:58 +02:00
|
|
|
alias Mobilizon.Service.GlobalSearch.{EventResult, GroupResult}
|
|
|
|
|
|
|
|
interface :event_search_result do
|
|
|
|
field(:id, :id, description: "Internal ID for this event")
|
|
|
|
field(:uuid, :uuid, description: "The Event UUID")
|
|
|
|
field(:url, :string, description: "The ActivityPub Event URL")
|
|
|
|
field(:title, :string, description: "The event's title")
|
|
|
|
field(:begins_on, :datetime, description: "Datetime for when the event begins")
|
|
|
|
field(:ends_on, :datetime, description: "Datetime for when the event ends")
|
|
|
|
field(:status, :event_status, description: "Status of the event")
|
|
|
|
field(:picture, :media, description: "The event's picture")
|
|
|
|
field(:physical_address, :address, description: "The event's physical address")
|
|
|
|
field(:attributed_to, :actor, description: "Who the event is attributed to (often a group)")
|
|
|
|
field(:organizer_actor, :actor, description: "The event's organizer (as a person)")
|
|
|
|
field(:tags, list_of(:tag), description: "The event's tags")
|
|
|
|
field(:category, :event_category, description: "The event's category")
|
|
|
|
field(:options, :event_options, description: "The event options")
|
2022-09-27 10:50:14 +02:00
|
|
|
|
|
|
|
field(:participant_stats, :participant_stats,
|
|
|
|
description: "Statistics on the event's participants"
|
|
|
|
)
|
2022-08-26 16:08:58 +02:00
|
|
|
|
|
|
|
resolve_type(fn
|
|
|
|
%Event{}, _ ->
|
|
|
|
:event
|
|
|
|
|
|
|
|
%EventResult{}, _ ->
|
|
|
|
:event_result
|
|
|
|
|
|
|
|
_, _ ->
|
|
|
|
nil
|
|
|
|
end)
|
|
|
|
end
|
|
|
|
|
|
|
|
@desc "Search event result"
|
|
|
|
object :event_result do
|
|
|
|
interfaces([:event_search_result])
|
|
|
|
field(:id, :id, description: "Internal ID for this event")
|
|
|
|
field(:uuid, :uuid, description: "The Event UUID")
|
|
|
|
field(:url, :string, description: "The ActivityPub Event URL")
|
|
|
|
field(:title, :string, description: "The event's title")
|
|
|
|
field(:begins_on, :datetime, description: "Datetime for when the event begins")
|
|
|
|
field(:ends_on, :datetime, description: "Datetime for when the event ends")
|
|
|
|
field(:status, :event_status, description: "Status of the event")
|
|
|
|
field(:picture, :media, description: "The event's picture")
|
|
|
|
field(:physical_address, :address, description: "The event's physical address")
|
|
|
|
field(:attributed_to, :actor, description: "Who the event is attributed to (often a group)")
|
|
|
|
field(:organizer_actor, :actor, description: "The event's organizer (as a person)")
|
|
|
|
field(:tags, list_of(:tag), description: "The event's tags")
|
|
|
|
field(:category, :event_category, description: "The event's category")
|
|
|
|
field(:options, :event_options, description: "The event options")
|
2022-09-27 10:50:14 +02:00
|
|
|
|
|
|
|
field(:participant_stats, :participant_stats,
|
|
|
|
description: "Statistics on the event's participants"
|
|
|
|
)
|
2022-08-26 16:08:58 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
interface :group_search_result do
|
|
|
|
field(:id, :id, description: "Internal ID for this group")
|
|
|
|
field(:url, :string, description: "The ActivityPub actor's URL")
|
|
|
|
field(:type, :actor_type, description: "The type of Actor (Person, Group,…)")
|
|
|
|
field(:name, :string, description: "The actor's displayed name")
|
|
|
|
field(:domain, :string, description: "The actor's domain if (null if it's this instance)")
|
|
|
|
field(:summary, :string, description: "The actor's summary")
|
|
|
|
field(:preferred_username, :string, description: "The actor's preferred username")
|
|
|
|
field(:avatar, :media, description: "The actor's avatar media")
|
|
|
|
field(:banner, :media, description: "The actor's banner media")
|
|
|
|
field(:followers_count, :integer, description: "Number of followers for this actor")
|
|
|
|
field(:members_count, :integer, description: "Number of followers for this actor")
|
|
|
|
field(:physical_address, :address, description: "The type of the event's address")
|
|
|
|
|
|
|
|
resolve_type(fn
|
|
|
|
%Actor{type: :Group}, _ ->
|
|
|
|
:group
|
|
|
|
|
|
|
|
%GroupResult{}, _ ->
|
|
|
|
:group_result
|
|
|
|
|
|
|
|
_, _ ->
|
|
|
|
nil
|
|
|
|
end)
|
|
|
|
end
|
|
|
|
|
|
|
|
@desc "Search group result"
|
|
|
|
object :group_result do
|
|
|
|
interfaces([:group_search_result])
|
|
|
|
field(:id, :id, description: "Internal ID for this group")
|
|
|
|
field(:url, :string, description: "The ActivityPub actor's URL")
|
|
|
|
field(:type, :actor_type, description: "The type of Actor (Person, Group,…)")
|
|
|
|
field(:name, :string, description: "The actor's displayed name")
|
|
|
|
field(:domain, :string, description: "The actor's domain if (null if it's this instance)")
|
|
|
|
field(:summary, :string, description: "The actor's summary")
|
|
|
|
field(:preferred_username, :string, description: "The actor's preferred username")
|
|
|
|
field(:avatar, :media, description: "The actor's avatar media")
|
|
|
|
field(:banner, :media, description: "The actor's banner media")
|
|
|
|
field(:followers_count, :integer, description: "Number of followers for this actor")
|
|
|
|
field(:members_count, :integer, description: "Number of followers for this actor")
|
|
|
|
field(:physical_address, :address, description: "The type of the event's address")
|
|
|
|
end
|
2019-04-12 15:04:32 +02:00
|
|
|
|
|
|
|
@desc "Search persons result"
|
|
|
|
object :persons do
|
|
|
|
field(:total, non_null(:integer), description: "Total elements")
|
|
|
|
field(:elements, non_null(list_of(:person)), description: "Person elements")
|
|
|
|
end
|
|
|
|
|
|
|
|
@desc "Search groups result"
|
|
|
|
object :groups do
|
|
|
|
field(:total, non_null(:integer), description: "Total elements")
|
2022-08-26 16:08:58 +02:00
|
|
|
field(:elements, non_null(list_of(:group_search_result)), description: "Group elements")
|
2019-04-12 15:04:32 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
@desc "Search events result"
|
|
|
|
object :events do
|
|
|
|
field(:total, non_null(:integer), description: "Total elements")
|
2022-08-26 16:08:58 +02:00
|
|
|
field(:elements, non_null(list_of(:event_search_result)), description: "Event elements")
|
2019-04-12 15:04:32 +02:00
|
|
|
end
|
|
|
|
|
2020-11-19 17:06:28 +01:00
|
|
|
@desc """
|
|
|
|
A entity that can be interacted with from a remote instance
|
|
|
|
"""
|
2020-11-06 11:34:32 +01:00
|
|
|
interface :interactable do
|
|
|
|
field(:url, :string, description: "A public URL for the entity")
|
|
|
|
|
|
|
|
resolve_type(fn
|
|
|
|
%Actor{type: :Group}, _ ->
|
|
|
|
:group
|
|
|
|
|
|
|
|
%Event{}, _ ->
|
|
|
|
:event
|
|
|
|
|
|
|
|
_, _ ->
|
|
|
|
nil
|
|
|
|
end)
|
|
|
|
end
|
|
|
|
|
2021-11-06 14:37:45 +01:00
|
|
|
enum :event_type do
|
|
|
|
value(:in_person,
|
|
|
|
description:
|
|
|
|
"The event will happen in person. It can also be livestreamed, but has a physical address"
|
|
|
|
)
|
|
|
|
|
|
|
|
value(:online, description: "The event will only happen online. It has no physical address")
|
|
|
|
end
|
|
|
|
|
2022-08-26 16:08:58 +02:00
|
|
|
enum :search_target do
|
|
|
|
value(:internal,
|
|
|
|
description: "Search on content from this instance and from the followed instances"
|
|
|
|
)
|
|
|
|
|
|
|
|
value(:global, description: "Search using the global fediverse search")
|
|
|
|
end
|
|
|
|
|
2022-09-26 10:29:20 +02:00
|
|
|
enum :search_group_sort_options do
|
|
|
|
value(:match_desc, description: "The pertinence of the result")
|
|
|
|
value(:member_count_desc, description: "The members count of the group")
|
|
|
|
end
|
|
|
|
|
|
|
|
enum :search_event_sort_options do
|
|
|
|
value(:match_desc, description: "The pertinence of the result")
|
|
|
|
value(:start_time_desc, description: "The start date of the result")
|
|
|
|
value(:created_at_desc, description: "When the event was published")
|
|
|
|
value(:created_at_asc, description: "When the event was published")
|
|
|
|
value(:participant_count_desc, description: "With the most participants")
|
|
|
|
end
|
|
|
|
|
2019-04-12 15:04:32 +02:00
|
|
|
object :search_queries do
|
|
|
|
@desc "Search persons"
|
|
|
|
field :search_persons, :persons do
|
2020-11-19 17:06:28 +01:00
|
|
|
arg(:term, :string, default_value: "", description: "Search term")
|
|
|
|
arg(:page, :integer, default_value: 1, description: "Result page")
|
|
|
|
arg(:limit, :integer, default_value: 10, description: "Results limit per page")
|
2019-04-12 15:04:32 +02:00
|
|
|
|
2020-01-26 20:34:25 +01:00
|
|
|
resolve(&Search.search_persons/3)
|
2019-04-12 15:04:32 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
@desc "Search groups"
|
|
|
|
field :search_groups, :groups do
|
2020-11-19 17:06:28 +01:00
|
|
|
arg(:term, :string, default_value: "", description: "Search term")
|
2020-08-05 16:44:08 +02:00
|
|
|
arg(:location, :string, description: "A geohash for coordinates")
|
2020-11-19 17:06:28 +01:00
|
|
|
|
2021-11-06 10:09:54 +01:00
|
|
|
arg(:exclude_my_groups, :boolean,
|
|
|
|
description: "Whether to include the groups the current actor is member or follower"
|
|
|
|
)
|
|
|
|
|
|
|
|
arg(:minimum_visibility, :group_visibility,
|
|
|
|
description: "The minimum visibility the group must have"
|
|
|
|
)
|
|
|
|
|
2020-11-19 17:06:28 +01:00
|
|
|
arg(:radius, :float,
|
|
|
|
default_value: 50,
|
|
|
|
description: "Radius around the location to search in"
|
|
|
|
)
|
|
|
|
|
2022-08-26 16:08:58 +02:00
|
|
|
arg(:language_one_of, list_of(:string),
|
|
|
|
description: "The list of languages this event can be in"
|
|
|
|
)
|
2022-09-27 10:50:14 +02:00
|
|
|
|
|
|
|
arg(:boost_languages, list_of(:string),
|
|
|
|
description: "The user's languages that can benefit from a boost in search results"
|
|
|
|
)
|
2022-08-26 16:08:58 +02:00
|
|
|
|
|
|
|
arg(:search_target, :search_target,
|
|
|
|
default_value: :internal,
|
|
|
|
description: "The target of the search (internal or global)"
|
|
|
|
)
|
|
|
|
|
2022-09-01 10:00:17 +02:00
|
|
|
arg(:bbox, :string, description: "The bbox to search groups into")
|
|
|
|
arg(:zoom, :integer, description: "The zoom level for searching groups")
|
|
|
|
|
2020-11-19 17:06:28 +01:00
|
|
|
arg(:page, :integer, default_value: 1, description: "Result page")
|
|
|
|
arg(:limit, :integer, default_value: 10, description: "Results limit per page")
|
2019-04-12 15:04:32 +02:00
|
|
|
|
2022-09-26 10:29:20 +02:00
|
|
|
arg(:sort_by, :search_group_sort_options,
|
|
|
|
default_value: :match_desc,
|
|
|
|
description: "How to sort search results"
|
|
|
|
)
|
|
|
|
|
2020-01-26 20:34:25 +01:00
|
|
|
resolve(&Search.search_groups/3)
|
2019-04-12 15:04:32 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
@desc "Search events"
|
|
|
|
field :search_events, :events do
|
2020-07-31 17:52:26 +02:00
|
|
|
arg(:term, :string, default_value: "")
|
2020-08-03 17:34:50 +02:00
|
|
|
arg(:tags, :string, description: "A comma-separated string listing the tags")
|
2020-07-31 17:52:26 +02:00
|
|
|
arg(:location, :string, description: "A geohash for coordinates")
|
2021-11-06 14:37:45 +01:00
|
|
|
arg(:type, :event_type, description: "Whether the event is online or in person")
|
2022-03-28 17:42:59 +02:00
|
|
|
arg(:category, :string, description: "The category for the event")
|
2020-11-19 17:06:28 +01:00
|
|
|
|
2022-08-22 12:12:09 +02:00
|
|
|
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"
|
|
|
|
)
|
|
|
|
|
2022-08-26 16:08:58 +02:00
|
|
|
arg(:language_one_of, list_of(:string),
|
|
|
|
description: "The list of languages this event can be in"
|
|
|
|
)
|
2022-09-27 10:50:14 +02:00
|
|
|
|
|
|
|
arg(:boost_languages, list_of(:string),
|
|
|
|
description: "The user's languages that can benefit from a boost in search results"
|
|
|
|
)
|
2022-08-26 16:08:58 +02:00
|
|
|
|
|
|
|
arg(:search_target, :search_target,
|
|
|
|
default_value: :internal,
|
|
|
|
description: "The target of the search (internal or global)"
|
|
|
|
)
|
|
|
|
|
2020-11-19 17:06:28 +01:00
|
|
|
arg(:radius, :float,
|
|
|
|
default_value: 50,
|
|
|
|
description: "Radius around the location to search in"
|
|
|
|
)
|
|
|
|
|
2022-09-01 10:00:17 +02:00
|
|
|
arg(:bbox, :string, description: "The bbox to search events into")
|
|
|
|
arg(:zoom, :integer, description: "The zoom level for searching events")
|
|
|
|
|
2020-11-19 17:06:28 +01:00
|
|
|
arg(:page, :integer, default_value: 1, description: "Result page")
|
|
|
|
arg(:limit, :integer, default_value: 10, description: "Results limit per page")
|
|
|
|
arg(:begins_on, :datetime, description: "Filter events by their start date")
|
|
|
|
arg(:ends_on, :datetime, description: "Filter events by their end date")
|
2019-04-12 15:04:32 +02:00
|
|
|
|
2022-09-26 10:29:20 +02:00
|
|
|
arg(:sort_by, :search_event_sort_options,
|
|
|
|
default_value: :match_desc,
|
|
|
|
description: "How to sort search results"
|
|
|
|
)
|
|
|
|
|
2020-01-26 20:34:25 +01:00
|
|
|
resolve(&Search.search_events/3)
|
2019-04-12 15:04:32 +02:00
|
|
|
end
|
2020-11-06 11:34:32 +01:00
|
|
|
|
|
|
|
@desc "Interact with an URI"
|
|
|
|
field :interact, :interactable do
|
|
|
|
arg(:uri, non_null(:string), description: "The URI for to interact with")
|
|
|
|
|
|
|
|
resolve(&Search.interact/3)
|
|
|
|
end
|
2019-04-12 15:04:32 +02:00
|
|
|
end
|
|
|
|
end
|