From c9f9ec04c8b7c24b47acb3f5a00f596b699c2c82 Mon Sep 17 00:00:00 2001 From: Mint Date: Thu, 21 Nov 2024 02:13:10 +0300 Subject: [PATCH 1/8] Meilisearch: use PUT method for indexing Mix task See https://github.com/meilisearch/meilisearch/issues/2619 --- lib/mix/tasks/pleroma/search/meilisearch.ex | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/mix/tasks/pleroma/search/meilisearch.ex b/lib/mix/tasks/pleroma/search/meilisearch.ex index 8379a0c252..389b8a564c 100644 --- a/lib/mix/tasks/pleroma/search/meilisearch.ex +++ b/lib/mix/tasks/pleroma/search/meilisearch.ex @@ -28,7 +28,7 @@ def run(["index"]) do end {:ok, _} = - meili_post( + meili_put( "/indexes/objects/settings/ranking-rules", [ "published:desc", @@ -42,7 +42,7 @@ def run(["index"]) do ) {:ok, _} = - meili_post( + meili_put( "/indexes/objects/settings/searchable-attributes", [ "content" From d65f768b59649de5ed5e76d7dd8248c76fd81a9f Mon Sep 17 00:00:00 2001 From: Mint Date: Thu, 21 Nov 2024 02:14:55 +0300 Subject: [PATCH 2/8] Meilisearch: stop attempting to index posts with nil date --- lib/pleroma/search/meilisearch.ex | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/pleroma/search/meilisearch.ex b/lib/pleroma/search/meilisearch.ex index 9bba5b30f8..cafae80990 100644 --- a/lib/pleroma/search/meilisearch.ex +++ b/lib/pleroma/search/meilisearch.ex @@ -122,6 +122,7 @@ def object_to_search_data(object) do # Only index public or unlisted Notes if not is_nil(object) and object.data["type"] == "Note" and not is_nil(object.data["content"]) and + not is_nil(object.data["published"]) and (Pleroma.Constants.as_public() in object.data["to"] or Pleroma.Constants.as_public() in object.data["cc"]) and object.data["content"] not in ["", "."] do From 3a82a51a6e8b25c2e58e75329e12a090ad977519 Mon Sep 17 00:00:00 2001 From: Mint Date: Thu, 21 Nov 2024 02:16:36 +0300 Subject: [PATCH 3/8] Docs: fix OTP mix task command for Meilisearch --- docs/configuration/search.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/docs/configuration/search.md b/docs/configuration/search.md index d34f84d4f9..de1a722030 100644 --- a/docs/configuration/search.md +++ b/docs/configuration/search.md @@ -73,7 +73,7 @@ you have to get the _private key_, which is actually used for authentication. === "OTP" ```sh - ./bin/pleroma_ctl search.meilisearch show-keys + ./bin/pleroma_ctl meilisearch show-keys ``` === "From Source" @@ -103,7 +103,7 @@ To start the initial indexing, run the `index` command: === "OTP" ```sh - ./bin/pleroma_ctl search.meilisearch index + ./bin/pleroma_ctl meilisearch index ``` === "From Source" @@ -118,7 +118,7 @@ of indexing and how many posts have actually been indexed, use the `stats` comma === "OTP" ```sh - ./bin/pleroma_ctl search.meilisearch stats + ./bin/pleroma_ctl meilisearch stats ``` === "From Source" @@ -133,7 +133,7 @@ use the `clear` command: === "OTP" ```sh - ./bin/pleroma_ctl search.meilisearch clear + ./bin/pleroma_ctl meilisearch clear ``` === "From Source" From af7de4c17a0f146a3048d5b2742a292e69bbbb70 Mon Sep 17 00:00:00 2001 From: Mint Date: Thu, 21 Nov 2024 02:17:53 +0300 Subject: [PATCH 4/8] Changelog --- changelog.d/meilisearch-misc-fixes.fix | 1 + 1 file changed, 1 insertion(+) create mode 100644 changelog.d/meilisearch-misc-fixes.fix diff --git a/changelog.d/meilisearch-misc-fixes.fix b/changelog.d/meilisearch-misc-fixes.fix new file mode 100644 index 0000000000..0f127d3a8d --- /dev/null +++ b/changelog.d/meilisearch-misc-fixes.fix @@ -0,0 +1 @@ +Miscellaneous fixes for Meilisearch support From da7132caba49777c25413efc8adc90d27576b07f Mon Sep 17 00:00:00 2001 From: Mint Date: Thu, 21 Nov 2024 02:40:27 +0300 Subject: [PATCH 5/8] Remove unused import --- lib/mix/tasks/pleroma/search/meilisearch.ex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/mix/tasks/pleroma/search/meilisearch.ex b/lib/mix/tasks/pleroma/search/meilisearch.ex index 389b8a564c..edce9e8717 100644 --- a/lib/mix/tasks/pleroma/search/meilisearch.ex +++ b/lib/mix/tasks/pleroma/search/meilisearch.ex @@ -9,7 +9,7 @@ defmodule Mix.Tasks.Pleroma.Search.Meilisearch do import Ecto.Query import Pleroma.Search.Meilisearch, - only: [meili_post: 2, meili_put: 2, meili_get: 1, meili_delete: 1] + only: [meili_put: 2, meili_get: 1, meili_delete: 1] def run(["index"]) do start_pleroma() From 551534f3eeae0062a06e10a322ba17a6d4ee8b9a Mon Sep 17 00:00:00 2001 From: Lain Soykaf Date: Thu, 21 Nov 2024 16:07:09 +0400 Subject: [PATCH 6/8] B ReleaseTasks: Fix task module finding. --- changelog.d/module-search-in-pleroma-ctl.fix | 1 + lib/pleroma/release_tasks.ex | 23 +++++++++++++------- test/pleroma/release_tasks_test.exs | 19 ++++++++++++++++ 3 files changed, 35 insertions(+), 8 deletions(-) create mode 100644 changelog.d/module-search-in-pleroma-ctl.fix create mode 100644 test/pleroma/release_tasks_test.exs diff --git a/changelog.d/module-search-in-pleroma-ctl.fix b/changelog.d/module-search-in-pleroma-ctl.fix new file mode 100644 index 0000000000..d32fe3f33f --- /dev/null +++ b/changelog.d/module-search-in-pleroma-ctl.fix @@ -0,0 +1 @@ +Fix pleroma_ctl mix task calls sometimes not being found diff --git a/lib/pleroma/release_tasks.ex b/lib/pleroma/release_tasks.ex index bcfcd12435..af2d35c8fa 100644 --- a/lib/pleroma/release_tasks.ex +++ b/lib/pleroma/release_tasks.ex @@ -16,17 +16,24 @@ def run(args) do end end + def find_module(task) do + module_name = + task + |> String.split(".") + |> Enum.map(&String.capitalize/1) + |> then(fn x -> [Mix, Tasks, Pleroma] ++ x end) + |> Module.concat() + + case Code.ensure_loaded(module_name) do + {:module, _} -> module_name + _ -> nil + end + end + defp mix_task(task, args) do Application.load(:pleroma) - {:ok, modules} = :application.get_key(:pleroma, :modules) - module = - Enum.find(modules, fn module -> - module = Module.split(module) - - match?(["Mix", "Tasks", "Pleroma" | _], module) and - String.downcase(List.last(module)) == task - end) + module = find_module(task) if module do module.run(args) diff --git a/test/pleroma/release_tasks_test.exs b/test/pleroma/release_tasks_test.exs new file mode 100644 index 0000000000..5a4293189a --- /dev/null +++ b/test/pleroma/release_tasks_test.exs @@ -0,0 +1,19 @@ +# Pleroma: A lightweight social networking server +# Copyright © 2017-2022 Pleroma Authors +# SPDX-License-Identifier: AGPL-3.0-only + +defmodule Pleroma.ReleaseTaskTest do + use Pleroma.DataCase, async: true + + alias Pleroma.ReleaseTasks + + test "finding the module" do + task = "search.meilisearch" + assert Mix.Tasks.Pleroma.Search.Meilisearch == ReleaseTasks.find_module(task) + + task = "user" + assert Mix.Tasks.Pleroma.User == ReleaseTasks.find_module(task) + + refute ReleaseTasks.find_module("doesnt.exist") + end +end From 14dbf789b3e0e84f588999954f07a378a6ccfcf6 Mon Sep 17 00:00:00 2001 From: Lain Soykaf Date: Thu, 21 Nov 2024 16:32:05 +0400 Subject: [PATCH 7/8] Linting --- test/pleroma/{release_tasks_test.exs => release_task_test.exs} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename test/pleroma/{release_tasks_test.exs => release_task_test.exs} (100%) diff --git a/test/pleroma/release_tasks_test.exs b/test/pleroma/release_task_test.exs similarity index 100% rename from test/pleroma/release_tasks_test.exs rename to test/pleroma/release_task_test.exs From 462a6a2000d10e3b6047bc72143ff239caf40186 Mon Sep 17 00:00:00 2001 From: Mint Date: Thu, 21 Nov 2024 16:52:30 +0300 Subject: [PATCH 8/8] Revert "Docs: fix OTP mix task command for Meilisearch" This reverts commit 3a82a51a6e8b25c2e58e75329e12a090ad977519. --- docs/configuration/search.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/docs/configuration/search.md b/docs/configuration/search.md index de1a722030..d34f84d4f9 100644 --- a/docs/configuration/search.md +++ b/docs/configuration/search.md @@ -73,7 +73,7 @@ you have to get the _private key_, which is actually used for authentication. === "OTP" ```sh - ./bin/pleroma_ctl meilisearch show-keys + ./bin/pleroma_ctl search.meilisearch show-keys ``` === "From Source" @@ -103,7 +103,7 @@ To start the initial indexing, run the `index` command: === "OTP" ```sh - ./bin/pleroma_ctl meilisearch index + ./bin/pleroma_ctl search.meilisearch index ``` === "From Source" @@ -118,7 +118,7 @@ of indexing and how many posts have actually been indexed, use the `stats` comma === "OTP" ```sh - ./bin/pleroma_ctl meilisearch stats + ./bin/pleroma_ctl search.meilisearch stats ``` === "From Source" @@ -133,7 +133,7 @@ use the `clear` command: === "OTP" ```sh - ./bin/pleroma_ctl meilisearch clear + ./bin/pleroma_ctl search.meilisearch clear ``` === "From Source"