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.Meilisearch do
7 require Pleroma.Constants
15 endpoint = Pleroma.Config.get([Pleroma.Search.Meilisearch, :url])
19 "#{endpoint}/indexes/objects/settings/ranking-rules",
33 Pleroma.Repo.transaction(
37 # Only index public posts which are notes and have some text
39 fragment("data->>'type' = 'Note'") and
40 fragment("LENGTH(data->>'source') > 0") and
41 fragment("data->'to' \\? ?", ^Pleroma.Constants.as_public()),
42 order_by: fragment("data->'published' DESC")
46 |> Stream.chunk_every(chunk_size)
47 |> Stream.transform(0, fn objects, acc ->
48 new_acc = acc + Enum.count(objects)
50 IO.puts("Indexed #{new_acc} entries")
54 |> Stream.map(fn objects ->
55 Enum.map(objects, fn object ->
57 %{id: object.id, source: data["source"], ap: data["id"]}
60 |> Stream.each(fn objects ->
63 "#{endpoint}/indexes/objects/documents",
64 Jason.encode!(objects)
76 endpoint = Pleroma.Config.get([Pleroma.Search.Meilisearch, :url])
78 {:ok, _} = Pleroma.HTTP.request(:delete, "#{endpoint}/indexes/objects/documents", "", [], [])