commit: a9be4907c0d7b34e5564584d2d040632c32f2aa3
parent 1261c43a7af48ed6e6753461944659391c4c58cc
Author: Lain Soykaf <lain@lain.com>
Date: Thu, 16 May 2024 10:47:24 +0400
SearchBackend: Add drop_index
Diffstat:
5 files changed, 45 insertions(+), 4 deletions(-)
diff --git a/lib/mix/tasks/pleroma/search/indexer.ex b/lib/mix/tasks/pleroma/search/indexer.ex
@@ -9,9 +9,23 @@ defmodule Mix.Tasks.Pleroma.Search.Indexer do
alias Pleroma.Workers.SearchIndexingWorker
def run(["create_index"]) do
- Application.ensure_all_started(:pleroma)
+ start_pleroma()
+
+ with :ok <- Pleroma.Config.get([Pleroma.Search, :module]).create_index() do
+ IO.puts("Index created")
+ else
+ e -> IO.puts("Could not create index: #{inspect(e)}")
+ end
+ end
+
+ def run(["drop_index"]) do
+ start_pleroma()
- Pleroma.Config.get([Pleroma.Search, :module]).create_index()
+ with :ok <- Pleroma.Config.get([Pleroma.Search, :module]).drop_index() do
+ IO.puts("Index dropped")
+ else
+ e -> IO.puts("Could not drop index: #{inspect(e)}")
+ end
end
def run(["index" | options]) do
diff --git a/lib/pleroma/search/database_search.ex b/lib/pleroma/search/database_search.ex
@@ -48,6 +48,12 @@ defmodule Pleroma.Search.DatabaseSearch do
@impl true
def remove_from_index(_object), do: :ok
+ @impl true
+ def create_index, do: :ok
+
+ @impl true
+ def drop_index, do: :ok
+
def maybe_restrict_author(query, %User{} = author) do
Activity.Queries.by_author(query, author)
end
diff --git a/lib/pleroma/search/meilisearch.ex b/lib/pleroma/search/meilisearch.ex
@@ -10,6 +10,12 @@ defmodule Pleroma.Search.Meilisearch do
@behaviour Pleroma.Search.SearchBackend
+ @impl true
+ def create_index, do: :ok
+
+ @impl true
+ def drop_index, do: :ok
+
defp meili_headers do
private_key = Config.get([Pleroma.Search.Meilisearch, :private_key])
diff --git a/lib/pleroma/search/qdrant_search.ex b/lib/pleroma/search/qdrant_search.ex
@@ -11,11 +11,21 @@ defmodule Pleroma.Search.QdrantSearch do
@impl true
def create_index() do
payload = Pleroma.Config.get([Pleroma.Search.QdrantSearch, :qdrant_index_configuration])
- QdrantClient.put("/collections/posts", payload)
+
+ with {:ok, %{status: 200}} <- QdrantClient.put("/collections/posts", payload) do
+ :ok
+ else
+ e -> {:error, e}
+ end
end
+ @impl true
def drop_index() do
- QdrantClient.delete("/collections/posts")
+ with {:ok, %{status: 200}} <- QdrantClient.delete("/collections/posts") do
+ :ok
+ else
+ e -> {:error, e}
+ end
end
def get_embedding(text) do
diff --git a/lib/pleroma/search/search_backend.ex b/lib/pleroma/search/search_backend.ex
@@ -26,4 +26,9 @@ defmodule Pleroma.Search.SearchBackend do
Create the index
"""
@callback create_index() :: :ok | {:error, any()}
+
+ @doc """
+ Drop the index
+ """
+ @callback drop_index() :: :ok | {:error, any()}
end