SearchBackend: Add drop_index

This commit is contained in:
Lain Soykaf 2024-05-16 10:47:24 +04:00
parent 1261c43a7a
commit a9be4907c0
5 changed files with 45 additions and 4 deletions

View file

@ -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()
Pleroma.Config.get([Pleroma.Search, :module]).create_index()
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()
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

View file

@ -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

View file

@ -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])

View file

@ -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

View file

@ -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