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
14 @shortdoc "Manages elasticsearch"
16 def run(["import", "activities" | _rest]) do
19 from(a in Activity, where: not ilike(a.actor, "%/relay"))
20 |> where([a], fragment("(? ->> 'type'::text) = 'Create'", a.data))
21 |> Activity.with_preloaded_object()
22 |> Activity.with_preloaded_user_actor()
23 |> get_all(:activities)
26 def run(["import", "users" | _rest]) do
29 from(u in User, where: u.nickname not in ["internal.fetch", "relay"])
33 def run(["import", "hashtags" | _rest]) do
38 |> Pleroma.Elasticsearch.bulk_post(:hashtags)
41 defp get_all(query, index, max_id \\ nil) do
42 params = %{limit: 1000}
48 Map.put(params, :max_id, max_id)
53 |> Pagination.fetch_paginated(params)
59 |> Pleroma.Elasticsearch.bulk_post(index)
61 get_all(query, index, List.last(res).id)