Add a search backend behaviour
This commit is contained in:
parent
4f2637acc6
commit
6f2f457751
|
@ -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 @@ def search(user, search_query, options \\ []) 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
|
||||
|
|
|
@ -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 @@ def object_to_search_data(object) do
|
|||
end
|
||||
end
|
||||
|
||||
@impl true
|
||||
def add_to_index(activity) do
|
||||
maybe_search_data = object_to_search_data(activity.object)
|
||||
|
||||
|
@ -159,6 +162,7 @@ def add_to_index(activity) do
|
|||
end
|
||||
end
|
||||
|
||||
@impl true
|
||||
def remove_from_index(object) do
|
||||
meili_delete!("/indexes/objects/documents/#{object.id}")
|
||||
end
|
||||
|
|
|
@ -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
|
Loading…
Reference in New Issue