diff --git a/lib/mix/tasks/pleroma/search.ex b/lib/mix/tasks/pleroma/search.ex index 9e0f376c3..4e8e480d4 100644 --- a/lib/mix/tasks/pleroma/search.ex +++ b/lib/mix/tasks/pleroma/search.ex @@ -15,13 +15,15 @@ def run(["import" | _rest]) do start_pleroma() from(a in Activity, where: not ilike(a.actor, "%/relay")) + |> where([a], fragment("(? ->> 'type'::text) = 'Create'", a.data)) |> Activity.with_preloaded_object() |> Activity.with_preloaded_user_actor() |> get_all end defp get_all(query, max_id \\ nil) do - params = %{limit: 20} + IO.puts(max_id) + params = %{limit: 2000} params = if max_id == nil do @@ -38,6 +40,12 @@ defp get_all(query, max_id \\ nil) do :ok else res + |> Enum.filter(fn x -> + t = x.object + |> Map.get(:data, %{}) + |> Map.get("type", "") + t == "Note" + end) |> Pleroma.Elasticsearch.bulk_post(:activities) get_all(query, List.last(res).id) diff --git a/lib/pleroma/search/elasticsearch.ex b/lib/pleroma/search/elasticsearch.ex index af2e13e48..4c0127f0f 100644 --- a/lib/pleroma/search/elasticsearch.ex +++ b/lib/pleroma/search/elasticsearch.ex @@ -2,6 +2,7 @@ defmodule Pleroma.Search.Elasticsearch do @behaviour Pleroma.Search alias Pleroma.Web.MastodonAPI.StatusView + alias Pleroma.Web.ActivityPub.Visibility defp to_es(term) when is_binary(term) do %{ @@ -62,6 +63,7 @@ def search(%{assigns: %{user: user}} = _conn, %{q: query} = _params, _options) d |> Map.get("hits", []) |> Enum.map(fn result -> result["_id"] end) |> Pleroma.Activity.all_by_ids_with_object() + |> Enum.filter(fn x -> Visibility.visible_for_user?(x, user) end) %{ "accounts" => [],