summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorEkaterina Vaartis <vaartis@kotobank.ch>2021-12-20 22:38:50 +0300
committerEkaterina Vaartis <vaartis@kotobank.ch>2022-10-10 20:19:09 +0300
commit6f2f457751ea09507045e6dd5d5869a14befd3d1 (patch)
tree194d872a68903f827bf8edb8b1e2900c58f85f04 /lib
parent4f2637acc6c46ea39ae38e869903e7ffcc38b34d (diff)
downloadpleroma-6f2f457751ea09507045e6dd5d5869a14befd3d1.tar.gz
pleroma-6f2f457751ea09507045e6dd5d5869a14befd3d1.zip
Add a search backend behaviour
Diffstat (limited to 'lib')
-rw-r--r--lib/pleroma/search/database_search.ex5
-rw-r--r--lib/pleroma/search/meilisearch.ex4
-rw-r--r--lib/pleroma/search/search_backend.ex17
3 files changed, 26 insertions, 0 deletions
diff --git a/lib/pleroma/search/database_search.ex b/lib/pleroma/search/database_search.ex
index 5a8b8ca67..3735a5fab 100644
--- a/lib/pleroma/search/database_search.ex
+++ b/lib/pleroma/search/database_search.ex
@@ -13,6 +13,8 @@ defmodule Pleroma.Search.DatabaseSearch do
import Ecto.Query
+ @behaviour Pleroma.Search.SearchBackend
+
def search(user, search_query, options \\ []) do
index_type = if Pleroma.Config.get([:database, :rum_enabled]), do: :rum, else: :gin
limit = Enum.min([Keyword.get(options, :limit), 40])
@@ -45,7 +47,10 @@ defmodule Pleroma.Search.DatabaseSearch do
end
end
+ @impl true
def add_to_index(_activity), do: nil
+
+ @impl true
def remove_from_index(_object), do: nil
def maybe_restrict_author(query, %User{} = author) do
diff --git a/lib/pleroma/search/meilisearch.ex b/lib/pleroma/search/meilisearch.ex
index 21b44de86..33bbf8392 100644
--- a/lib/pleroma/search/meilisearch.ex
+++ b/lib/pleroma/search/meilisearch.ex
@@ -7,6 +7,8 @@ defmodule Pleroma.Search.Meilisearch do
import Pleroma.Search.DatabaseSearch
import Ecto.Query
+ @behaviour Pleroma.Search.SearchBackend
+
defp meili_headers do
private_key = Pleroma.Config.get([Pleroma.Search.Meilisearch, :private_key])
@@ -139,6 +141,7 @@ defmodule Pleroma.Search.Meilisearch do
end
end
+ @impl true
def add_to_index(activity) do
maybe_search_data = object_to_search_data(activity.object)
@@ -159,6 +162,7 @@ defmodule Pleroma.Search.Meilisearch do
end
end
+ @impl true
def remove_from_index(object) do
meili_delete!("/indexes/objects/documents/#{object.id}")
end
diff --git a/lib/pleroma/search/search_backend.ex b/lib/pleroma/search/search_backend.ex
new file mode 100644
index 000000000..ed6bfd329
--- /dev/null
+++ b/lib/pleroma/search/search_backend.ex
@@ -0,0 +1,17 @@
+defmodule Pleroma.Search.SearchBackend do
+ @doc """
+ Add the object associated with the activity to the search index.
+
+ The whole activity is passed, to allow filtering on things such as scope.
+ """
+ @callback add_to_index(activity :: Pleroma.Activity.t()) :: nil
+
+ @doc """
+ Remove the object from the index.
+
+ Just the object, as opposed to the whole activity, is passed, since the object
+ is what contains the actual content and there is no need for fitlering when removing
+ from index.
+ """
+ @callback remove_from_index(object :: Pleroma.Object.t()) :: nil
+end