Make the availability of media search configurable
This commit is contained in:
parent
54114a199b
commit
49eda427fd
5 changed files with 27 additions and 6 deletions
|
@ -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/",
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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"
|
||||
]
|
||||
|
|
Loading…
Reference in a new issue