Add participant info in event search results
Signed-off-by: Thomas Citharel <tcit@tcit.fr>
This commit is contained in:
@@ -183,7 +183,7 @@ defmodule Mobilizon.GraphQL.Resolvers.Event do
|
||||
stats.participant + stats.moderator + stats.administrator + stats.creator
|
||||
)}
|
||||
else
|
||||
{:ok, %{participant: stats.participant}}
|
||||
{:ok, %EventParticipantStats{participant: stats.participant}}
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -24,6 +24,7 @@ defmodule Mobilizon.GraphQL.Schema.SearchType do
|
||||
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")
|
||||
field(:participant_stats, :participant_stats, description: "Statistics on the event's participants")
|
||||
|
||||
resolve_type(fn
|
||||
%Event{}, _ ->
|
||||
@@ -54,6 +55,7 @@ defmodule Mobilizon.GraphQL.Schema.SearchType do
|
||||
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")
|
||||
field(:participant_stats, :participant_stats, description: "Statistics on the event's participants")
|
||||
end
|
||||
|
||||
interface :group_search_result do
|
||||
@@ -152,6 +154,19 @@ defmodule Mobilizon.GraphQL.Schema.SearchType do
|
||||
value(:global, description: "Search using the global fediverse search")
|
||||
end
|
||||
|
||||
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
|
||||
|
||||
object :search_queries do
|
||||
@desc "Search persons"
|
||||
field :search_persons, :persons do
|
||||
@@ -183,6 +198,7 @@ defmodule Mobilizon.GraphQL.Schema.SearchType do
|
||||
arg(:language_one_of, list_of(:string),
|
||||
description: "The list of languages this event can be in"
|
||||
)
|
||||
arg(:boost_languages, list_of(:string), description: "The user's languages that can benefit from a boost in search results")
|
||||
|
||||
arg(:search_target, :search_target,
|
||||
default_value: :internal,
|
||||
@@ -195,6 +211,11 @@ defmodule Mobilizon.GraphQL.Schema.SearchType do
|
||||
arg(:page, :integer, default_value: 1, description: "Result page")
|
||||
arg(:limit, :integer, default_value: 10, description: "Results limit per page")
|
||||
|
||||
arg(:sort_by, :search_group_sort_options,
|
||||
default_value: :match_desc,
|
||||
description: "How to sort search results"
|
||||
)
|
||||
|
||||
resolve(&Search.search_groups/3)
|
||||
end
|
||||
|
||||
@@ -217,6 +238,7 @@ defmodule Mobilizon.GraphQL.Schema.SearchType do
|
||||
arg(:language_one_of, list_of(:string),
|
||||
description: "The list of languages this event can be in"
|
||||
)
|
||||
arg(:boost_languages, list_of(:string), description: "The user's languages that can benefit from a boost in search results")
|
||||
|
||||
arg(:search_target, :search_target,
|
||||
default_value: :internal,
|
||||
@@ -236,6 +258,11 @@ defmodule Mobilizon.GraphQL.Schema.SearchType do
|
||||
arg(:begins_on, :datetime, description: "Filter events by their start date")
|
||||
arg(:ends_on, :datetime, description: "Filter events by their end date")
|
||||
|
||||
arg(:sort_by, :search_event_sort_options,
|
||||
default_value: :match_desc,
|
||||
description: "How to sort search results"
|
||||
)
|
||||
|
||||
resolve(&Search.search_events/3)
|
||||
end
|
||||
|
||||
|
||||
@@ -541,7 +541,7 @@ defmodule Mobilizon.Events do
|
||||
|> filter_draft()
|
||||
|> filter_local_or_from_followed_instances_events()
|
||||
|> filter_public_visibility()
|
||||
|> event_order_begins_on_asc()
|
||||
|> event_order(args.sort_by)
|
||||
|> Page.build_page(page, limit, :begins_on)
|
||||
end
|
||||
|
||||
@@ -1272,15 +1272,14 @@ defmodule Mobilizon.Events do
|
||||
end
|
||||
end
|
||||
|
||||
@spec events_for_search_query(String.t()) :: Ecto.Query.t()
|
||||
defp events_for_search_query("") do
|
||||
Event
|
||||
|> distinct([e], asc: e.begins_on, asc: e.id)
|
||||
end
|
||||
# @spec events_for_search_query(String.t()) :: Ecto.Query.t()
|
||||
# defp events_for_search_query("") do
|
||||
# Event
|
||||
# |> join: rank in fragment("")
|
||||
# end
|
||||
|
||||
defp events_for_search_query(search_string) do
|
||||
from(event in Event,
|
||||
distinct: [asc: event.begins_on, asc: event.id],
|
||||
join: id_and_rank in matching_event_ids_and_ranks(search_string),
|
||||
on: id_and_rank.id == event.id
|
||||
)
|
||||
@@ -1820,6 +1819,13 @@ defmodule Mobilizon.Events do
|
||||
|> event_order_begins_on_asc()
|
||||
end
|
||||
|
||||
defp event_order(query, :match_desc), do: order_by(query, [e, f], desc: f.rank, asc: e.begins_on)
|
||||
defp event_order(query, :start_time_desc), do: order_by(query, [e], asc: e.begins_on)
|
||||
defp event_order(query, :created_at_desc), do: order_by(query, [e], desc: e.publish_at)
|
||||
defp event_order(query, :created_at_asc), do: order_by(query, [e], asc: e.publish_at)
|
||||
defp event_order(query, :participant_count_desc), do: order_by(query, [e], fragment("participant_stats->>'participant' DESC"))
|
||||
defp event_order(query, _), do: query
|
||||
|
||||
defp event_order_begins_on_asc(query),
|
||||
do: order_by(query, [e], asc: e.begins_on)
|
||||
|
||||
|
||||
@@ -13,7 +13,7 @@ defmodule Mobilizon.Service.GlobalSearch.EventResult do
|
||||
:category,
|
||||
:tags,
|
||||
:organizer_actor,
|
||||
:participants,
|
||||
:participant_stats,
|
||||
:physical_address
|
||||
]
|
||||
end
|
||||
|
||||
@@ -15,6 +15,15 @@ defmodule Mobilizon.Service.GlobalSearch.SearchMobilizon do
|
||||
@search_events_api "/api/v1/search/events"
|
||||
@search_groups_api "/api/v1/search/groups"
|
||||
|
||||
@sort_by_options %{
|
||||
match_desc: "-match",
|
||||
start_time_desc: "-startTime",
|
||||
created_at_desc: "-createdAt",
|
||||
created_at_asc: "createdAt",
|
||||
participant_count_desc: "-participantCount",
|
||||
member_count_desc: "-memberCount"
|
||||
}
|
||||
|
||||
@behaviour Provider
|
||||
|
||||
@impl Provider
|
||||
@@ -39,9 +48,11 @@ defmodule Mobilizon.Service.GlobalSearch.SearchMobilizon do
|
||||
end),
|
||||
distance: if(options[:radius], do: "#{options[:radius]}_km", else: nil),
|
||||
count: options[:limit],
|
||||
start: (options[:page] - 1) * options[:limit],
|
||||
start: (Keyword.get(options, :page, 1) - 1) * Keyword.get(options, :limit, 16),
|
||||
latlon: to_lat_lon(options[:location]),
|
||||
bbox: options[:bbox]
|
||||
bbox: options[:bbox],
|
||||
sortBy: Map.get(@sort_by_options, options[:sort_by]),
|
||||
boostLanguages: options[:boost_languages]
|
||||
)
|
||||
|> Keyword.take([
|
||||
:search,
|
||||
@@ -56,7 +67,8 @@ defmodule Mobilizon.Service.GlobalSearch.SearchMobilizon do
|
||||
:statusOneOf,
|
||||
:bbox,
|
||||
:start,
|
||||
:count
|
||||
:count,
|
||||
:sortBy
|
||||
])
|
||||
|> Keyword.reject(fn {_key, val} -> is_nil(val) end)
|
||||
|
||||
@@ -85,21 +97,25 @@ defmodule Mobilizon.Service.GlobalSearch.SearchMobilizon do
|
||||
|> Keyword.merge(
|
||||
term: options[:search],
|
||||
languageOneOf: options[:language_one_of],
|
||||
boostLanguages: options[:boost_languages],
|
||||
distance: if(options[:radius], do: "#{options[:radius]}_km", else: nil),
|
||||
count: options[:limit],
|
||||
start: (options[:page] - 1) * options[:limit],
|
||||
latlon: to_lat_lon(options[:location]),
|
||||
bbox: options[:bbox]
|
||||
bbox: options[:bbox],
|
||||
sortBy: Map.get(@sort_by_options, options[:sort_by])
|
||||
)
|
||||
|> Keyword.take([
|
||||
:search,
|
||||
:languageOneOf,
|
||||
:boostLanguages,
|
||||
:latlon,
|
||||
:distance,
|
||||
:sort,
|
||||
:start,
|
||||
:count,
|
||||
:bbox
|
||||
:bbox,
|
||||
:sortBy
|
||||
])
|
||||
|> Keyword.reject(fn {_key, val} -> is_nil(val) end)
|
||||
|
||||
@@ -179,6 +195,7 @@ defmodule Mobilizon.Service.GlobalSearch.SearchMobilizon do
|
||||
avatar: organizer_actor_avatar
|
||||
},
|
||||
physical_address: address,
|
||||
participant_stats: %{participant: data["participantCount"]},
|
||||
tags:
|
||||
Enum.map(data["tags"], fn tag ->
|
||||
tag = String.trim_leading(tag, "#")
|
||||
|
||||
Reference in New Issue
Block a user