1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
5 defmodule Mix.Tasks.Pleroma.Search do
10 alias Pleroma.Pagination
13 @shortdoc "Manages elasticsearch"
15 def run(["import", "activities" | _rest]) do
18 from(a in Activity, where: not ilike(a.actor, "%/relay"))
19 |> where([a], fragment("(? ->> 'type'::text) = 'Create'", a.data))
20 |> Activity.with_preloaded_object()
21 |> Activity.with_preloaded_user_actor()
22 |> get_all(:activities)
25 def run(["import", "users" | _rest]) do
28 from(u in User, where: not ilike(u.ap_id, "%/relay"))
32 defp get_all(query, index, max_id \\ nil) do
33 params = %{limit: 2000}
39 Map.put(params, :max_id, max_id)
44 |> Pagination.fetch_paginated(params)
50 |> Pleroma.Elasticsearch.bulk_post(index)
52 get_all(query, index, List.last(res).id)