Merge search behaviour change, and refactor elasticsearch #28

Merged
floatingghost merged 91 commits from elasticsearch-refactor into develop 2022-06-30 16:55:31 +00:00
3 changed files with 26 additions and 0 deletions
Showing only changes of commit 54b2a86f47 - Show all commits

View file

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

View file

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

View file

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