diff --git a/config/config.exs b/config/config.exs index 3fe4b344b..980b6fba4 100644 --- a/config/config.exs +++ b/config/config.exs @@ -864,7 +864,13 @@ config :pleroma, Pleroma.Web.WebFinger, domain: nil, update_nickname_on_user_fetch: true -config :pleroma, Pleroma.Search, module: Pleroma.Search.DatabaseSearch +config :pleroma, Pleroma.Search, + module: Pleroma.Search.DatabaseSearch, + extensions: %{ + # this features is placed in the ':extensions' section for clarity + # as this is not in the upstream, at least not yet + search_type_media: true + } config :pleroma, Pleroma.Search.Meilisearch, url: "http://127.0.0.1:7700/", diff --git a/lib/pleroma/search/database_search.ex b/lib/pleroma/search/database_search.ex index 6298b301a..c9472374d 100644 --- a/lib/pleroma/search/database_search.ex +++ b/lib/pleroma/search/database_search.ex @@ -44,7 +44,7 @@ def search(user, search_query, options \\ []) do |> maybe_restrict_local(user) |> maybe_restrict_author(author) |> maybe_restrict_blocked(user) - |> maybe_only_media(only_media) + |> maybe_restrict_media(only_media) |> Pagination.fetch_paginated( %{"offset" => offset, "limit" => limit, "skip_order" => index_type == :rum}, :offset @@ -176,11 +176,11 @@ def maybe_fetch(activities, user, search_query) do end end - def maybe_only_media(q, true) do + def maybe_restrict_media(q, true) do from([a, o] in q, where: fragment("not (?)->'attachment' = (?)", o.data, ^[]) ) end - def maybe_only_media(q, _), do: q + def maybe_restrict_media(q, _), do: q end diff --git a/lib/pleroma/search/meilisearch.ex b/lib/pleroma/search/meilisearch.ex index b0cf292a3..66a1c8754 100644 --- a/lib/pleroma/search/meilisearch.ex +++ b/lib/pleroma/search/meilisearch.ex @@ -98,7 +98,7 @@ def search(user, query, options \\ []) do |> maybe_restrict_local(user) |> maybe_restrict_author(author) |> maybe_restrict_blocked(user) - |> maybe_only_media(only_media) + |> maybe_restrict_media(only_media) |> maybe_fetch(user, query) |> order_by([object: obj], desc: obj.data["published"]) |> Pleroma.Repo.all() diff --git a/lib/pleroma/web/mastodon_api/controllers/search_controller.ex b/lib/pleroma/web/mastodon_api/controllers/search_controller.ex index c0110adb4..ef69e84f8 100644 --- a/lib/pleroma/web/mastodon_api/controllers/search_controller.ex +++ b/lib/pleroma/web/mastodon_api/controllers/search_controller.ex @@ -47,7 +47,19 @@ defp do_search(version, %{assigns: %{user: user}} = conn, %{q: query} = params) query = String.trim(query) options = search_options(params, user) timeout = Keyword.get(Repo.config(), :timeout, 15_000) - default_values = %{"statuses" => [], "media" => [], "accounts" => [], "hashtags" => []} + + default_values = + Map.new( + [ + "statuses", + if Pleroma.Config.get([Pleroma.Search, :extensions, :search_type_media], true) do + "media" + end, + "accounts", + "hashtags" + ], + fn x -> {x, []} end + ) result = default_values diff --git a/lib/pleroma/web/mastodon_api/views/instance_view.ex b/lib/pleroma/web/mastodon_api/views/instance_view.ex index 2b5354873..1f02e97c0 100644 --- a/lib/pleroma/web/mastodon_api/views/instance_view.ex +++ b/lib/pleroma/web/mastodon_api/views/instance_view.ex @@ -89,6 +89,9 @@ def features do if Config.get([:translator, :enabled], false) do "akkoma:machine_translation" end, + if Config.get([Pleroma.Search, :extensions, :search_type_media], true) do + "bnakkoma:search_type_media" + end, "custom_emoji_reactions", "pleroma:get:main/ostatus" ]