Remove redundant checks from backends' add_to_index/1
This commit is contained in:
parent
627c944fec
commit
a5c88eb39b
2 changed files with 26 additions and 34 deletions
|
|
@ -4,6 +4,7 @@ defmodule Pleroma.Search.Meilisearch do
|
||||||
|
|
||||||
alias Pleroma.Activity
|
alias Pleroma.Activity
|
||||||
alias Pleroma.Config.Getting, as: Config
|
alias Pleroma.Config.Getting, as: Config
|
||||||
|
alias Pleroma.Object
|
||||||
|
|
||||||
import Pleroma.Search.DatabaseSearch
|
import Pleroma.Search.DatabaseSearch
|
||||||
import Ecto.Query
|
import Ecto.Query
|
||||||
|
|
@ -155,28 +156,23 @@ defmodule Pleroma.Search.Meilisearch do
|
||||||
end
|
end
|
||||||
|
|
||||||
@impl true
|
@impl true
|
||||||
def add_to_index(activity) do
|
def add_to_index(%Activity{object: %Object{} = object} = activity) do
|
||||||
maybe_search_data = object_to_search_data(activity.object)
|
search_data = object_to_search_data(object)
|
||||||
|
|
||||||
if activity.data["type"] == "Create" and maybe_search_data do
|
result =
|
||||||
result =
|
meili_put(
|
||||||
meili_put(
|
"/indexes/objects/documents",
|
||||||
"/indexes/objects/documents",
|
[search_data]
|
||||||
[maybe_search_data]
|
)
|
||||||
)
|
|
||||||
|
|
||||||
with {:ok, %{"status" => "enqueued"}} <- result do
|
with {:ok, %{"status" => "enqueued"}} <- result do
|
||||||
# Added successfully
|
# Added successfully
|
||||||
:ok
|
|
||||||
else
|
|
||||||
_ ->
|
|
||||||
# There was an error, report it
|
|
||||||
Logger.error("Failed to add activity #{activity.id} to index: #{inspect(result)}")
|
|
||||||
{:error, result}
|
|
||||||
end
|
|
||||||
else
|
|
||||||
# The post isn't something we can search, that's ok
|
|
||||||
:ok
|
:ok
|
||||||
|
else
|
||||||
|
_ ->
|
||||||
|
# There was an error, report it
|
||||||
|
Logger.error("Failed to add activity #{activity.id} to index: #{inspect(result)}")
|
||||||
|
{:error, result}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@ defmodule Pleroma.Search.QdrantSearch do
|
||||||
|
|
||||||
alias Pleroma.Activity
|
alias Pleroma.Activity
|
||||||
alias Pleroma.Config.Getting, as: Config
|
alias Pleroma.Config.Getting, as: Config
|
||||||
|
alias Pleroma.Object
|
||||||
|
|
||||||
alias __MODULE__.OpenAIClient
|
alias __MODULE__.OpenAIClient
|
||||||
alias __MODULE__.QdrantClient
|
alias __MODULE__.QdrantClient
|
||||||
|
|
@ -82,23 +83,18 @@ defmodule Pleroma.Search.QdrantSearch do
|
||||||
end
|
end
|
||||||
|
|
||||||
@impl true
|
@impl true
|
||||||
def add_to_index(activity) do
|
def add_to_index(%Activity{object: %Object{} = object} = activity) do
|
||||||
# This will only index public or unlisted notes
|
search_data = object_to_search_data(object)
|
||||||
maybe_search_data = object_to_search_data(activity.object)
|
|
||||||
|
|
||||||
if activity.data["type"] == "Create" and maybe_search_data do
|
with {:ok, embedding} <- get_embedding(search_data.content),
|
||||||
with {:ok, embedding} <- get_embedding(maybe_search_data.content),
|
{:ok, %{status: 200}} <-
|
||||||
{:ok, %{status: 200}} <-
|
QdrantClient.put(
|
||||||
QdrantClient.put(
|
"/collections/posts/points",
|
||||||
"/collections/posts/points",
|
build_index_payload(activity, embedding)
|
||||||
build_index_payload(activity, embedding)
|
) do
|
||||||
) do
|
|
||||||
:ok
|
|
||||||
else
|
|
||||||
e -> {:error, e}
|
|
||||||
end
|
|
||||||
else
|
|
||||||
:ok
|
:ok
|
||||||
|
else
|
||||||
|
e -> {:error, e}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue