Make search a callback

This commit is contained in:
Ekaterina Vaartis 2022-08-27 00:19:08 +03:00
parent 119b2b847b
commit 102ebb42bd
3 changed files with 11 additions and 2 deletions

View File

@ -15,6 +15,7 @@ defmodule Pleroma.Search.DatabaseSearch do
@behaviour Pleroma.Search.SearchBackend @behaviour Pleroma.Search.SearchBackend
@impl true
def search(user, search_query, options \\ []) do def search(user, search_query, options \\ []) do
index_type = if Pleroma.Config.get([:database, :rum_enabled]), do: :rum, else: :gin index_type = if Pleroma.Config.get([:database, :rum_enabled]), do: :rum, else: :gin
limit = Enum.min([Keyword.get(options, :limit), 40]) limit = Enum.min([Keyword.get(options, :limit), 40])

View File

@ -75,6 +75,7 @@ def meili_delete!(path) do
) )
end end
@impl true
def search(user, query, options \\ []) do def search(user, query, options \\ []) do
limit = Enum.min([Keyword.get(options, :limit), 40]) limit = Enum.min([Keyword.get(options, :limit), 40])
offset = Keyword.get(options, :offset, 0) offset = Keyword.get(options, :offset, 0)

View File

@ -1,10 +1,17 @@
defmodule Pleroma.Search.SearchBackend do defmodule Pleroma.Search.SearchBackend do
@doc """
Search statuses with a query, restricting to only those the user should have access to.
"""
@callback search(user :: Pleroma.User.t(), query :: String.t(), options :: [any()]) :: [
Pleroma.Activity.t()
]
@doc """ @doc """
Add the object associated with the activity to the search index. Add the object associated with the activity to the search index.
The whole activity is passed, to allow filtering on things such as scope. The whole activity is passed, to allow filtering on things such as scope.
""" """
@callback add_to_index(activity :: Pleroma.Activity.t()) :: nil @callback add_to_index(activity :: Pleroma.Activity.t()) :: :ok | {:error, any()}
@doc """ @doc """
Remove the object from the index. Remove the object from the index.
@ -13,5 +20,5 @@ defmodule Pleroma.Search.SearchBackend do
is what contains the actual content and there is no need for fitlering when removing is what contains the actual content and there is no need for fitlering when removing
from index. from index.
""" """
@callback remove_from_index(object :: Pleroma.Object.t()) :: nil @callback remove_from_index(object :: Pleroma.Object.t()) :: {:ok, any()} | {:error, any()}
end end