Initial meilisearch implementation, doesn't delete posts yet
[akkoma] / lib / mix / tasks / pleroma / search / meilisearch.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.Meilisearch do
6 import Mix.Pleroma
7
8 import Ecto.Query
9
10 def run(["index"]) do
11 start_pleroma()
12
13 endpoint = Pleroma.Config.get([Pleroma.Search.Meilisearch, :url])
14
15 Pleroma.Repo.chunk_stream(
16 from(Pleroma.Object,
17 limit: 200,
18 where: fragment("data->>'type' = 'Note'") and fragment("LENGTH(data->>'source') > 0")
19 ),
20 100,
21 :batches
22 )
23 |> Stream.map(fn objects ->
24 Enum.map(objects, fn object ->
25 data = object.data
26 %{id: object.id, source: data["source"], ap: data["id"]}
27 end)
28 end)
29 |> Stream.each(fn activities ->
30 {:ok, _} =
31 Pleroma.HTTP.post(
32 "#{endpoint}/indexes/objects/documents",
33 Jason.encode!(activities)
34 )
35 end)
36 |> Stream.run()
37 end
38 end