Rename search.ex to database_search.ex and add search/2
This commit is contained in:
parent
0769f06bd1
commit
ea582fbf93
4 changed files with 11 additions and 7 deletions
|
@ -1,4 +1,4 @@
|
||||||
defmodule Pleroma.Search do
|
defmodule Pleroma.Search.DatabaseSearch do
|
||||||
def add_to_index(activity) do
|
def add_to_index(activity) do
|
||||||
search_module = Pleroma.Config.get([Pleroma.Search, :module])
|
search_module = Pleroma.Config.get([Pleroma.Search, :module])
|
||||||
|
|
||||||
|
@ -15,4 +15,10 @@ def remove_from_index(object) do
|
||||||
Task.start(fn -> search_module.remove_from_index(object) end)
|
Task.start(fn -> search_module.remove_from_index(object) end)
|
||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def search(query, options) do
|
||||||
|
search_module = Pleroma.Config.get([Pleroma.Search, :module], Pleroma.Activity)
|
||||||
|
|
||||||
|
search_module.search(options[:for_user], query, options)
|
||||||
|
end
|
||||||
end
|
end
|
|
@ -141,7 +141,7 @@ def insert(map, local \\ true, fake \\ false, bypass_actor_check \\ false) when
|
||||||
end)
|
end)
|
||||||
|
|
||||||
# Add local posts to search index
|
# Add local posts to search index
|
||||||
if local, do: Pleroma.Search.add_to_index(activity)
|
if local, do: Pleroma.Search.DatabaseSearch.add_to_index(activity)
|
||||||
|
|
||||||
{:ok, activity}
|
{:ok, activity}
|
||||||
else
|
else
|
||||||
|
|
|
@ -223,7 +223,7 @@ def handle(%{data: %{"type" => "Create"}} = activity, meta) do
|
||||||
Task.start(fn -> Pleroma.Web.RichMedia.Helpers.fetch_data_for_activity(activity) end)
|
Task.start(fn -> Pleroma.Web.RichMedia.Helpers.fetch_data_for_activity(activity) end)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
Pleroma.Search.add_to_index(Map.put(activity, :object, object))
|
Pleroma.Search.DatabaseSearch.add_to_index(Map.put(activity, :object, object))
|
||||||
|
|
||||||
meta =
|
meta =
|
||||||
meta
|
meta
|
||||||
|
@ -325,7 +325,7 @@ def handle(%{data: %{"type" => "Delete", "object" => deleted_object}} = object,
|
||||||
if result == :ok do
|
if result == :ok do
|
||||||
Notification.create_notifications(object)
|
Notification.create_notifications(object)
|
||||||
|
|
||||||
Pleroma.Search.remove_from_index(deleted_object)
|
Pleroma.Search.DatabaseSearch.remove_from_index(deleted_object)
|
||||||
|
|
||||||
{:ok, object, meta}
|
{:ok, object, meta}
|
||||||
else
|
else
|
||||||
|
|
|
@ -76,9 +76,7 @@ defp resource_search(_, "accounts", query, options) do
|
||||||
end
|
end
|
||||||
|
|
||||||
defp resource_search(_, "statuses", query, options) do
|
defp resource_search(_, "statuses", query, options) do
|
||||||
search_module = Pleroma.Config.get([Pleroma.Search, :module], Pleroma.Activity)
|
statuses = with_fallback(fn -> Pleroma.Search.DatabaseSearch.search(query, options) end)
|
||||||
|
|
||||||
statuses = with_fallback(fn -> search_module.search(options[:for_user], query, options) end)
|
|
||||||
|
|
||||||
StatusView.render("index.json",
|
StatusView.render("index.json",
|
||||||
activities: statuses,
|
activities: statuses,
|
||||||
|
|
Loading…
Reference in a new issue