make search provider configurable
[akkoma] / lib / mix / tasks / pleroma / search.ex
1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
4
5 defmodule Mix.Tasks.Pleroma.Search do
6 use Mix.Task
7 import Mix.Pleroma
8 import Ecto.Query
9 alias Pleroma.Activity
10 alias Pleroma.Pagination
11
12 @shortdoc "Manages elasticsearch"
13
14 def run(["import" | _rest]) do
15 start_pleroma()
16
17 from(a in Activity, where: not ilike(a.actor, "%/relay"))
18 |> Activity.with_preloaded_object()
19 |> Activity.with_preloaded_user_actor()
20 |> get_all
21 end
22
23 defp get_all(query, max_id \\ nil) do
24 params = %{limit: 20}
25
26 params =
27 if max_id == nil do
28 params
29 else
30 Map.put(params, :max_id, max_id)
31 end
32
33 res =
34 query
35 |> Pagination.fetch_paginated(params)
36
37 if res == [] do
38 :ok
39 else
40 res
41 |> Pleroma.Elasticsearch.bulk_post(:activities)
42
43 get_all(query, List.last(res).id)
44 end
45 end
46 end