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",
31 Pleroma.Repo.chunk_stream(
33 # Only index public posts which are notes and have some text
35 fragment("data->>'type' = 'Note'") and
36 fragment("LENGTH(data->>'source') > 0") and
37 fragment("data->'to' \\? ?", ^Pleroma.Constants.as_public())
42 |> Stream.map(fn objects ->
43 Enum.map(objects, fn object ->
45 %{id: object.id, source: data["source"], ap: data["id"]}
48 |> Stream.each(fn objects ->
51 "#{endpoint}/indexes/objects/documents",
52 Jason.encode!(objects)
55 IO.puts("Indexed #{Enum.count(objects)} entries")
63 endpoint = Pleroma.Config.get([Pleroma.Search.Meilisearch, :url])
65 {:ok, _} = Pleroma.HTTP.request(:delete, "#{endpoint}/indexes/objects/documents", "", [], [])