1 defmodule Pleroma.Search.Elasticsearch do
2 @behaviour Pleroma.Search
4 alias Pleroma.Web.MastodonAPI.StatusView
5 alias Pleroma.Web.ActivityPub.Visibility
7 defp to_es(term) when is_binary(term) do
18 defp to_es({:quoted, term}), do: to_es(term)
20 defp to_es({:filter, ["hashtag", query]}) do
30 defp to_es({:filter, [field, query]}) do
42 |> SearchParser.parse!()
47 def search(%{assigns: %{user: user}} = _conn, %{q: query} = _params, _options) do
51 must: parse(String.trim(query))
56 out = Pleroma.Elasticsearch.search_activities(q)
58 with {:ok, raw_results} <- out do
61 |> Map.get(:body, %{})
62 |> Map.get("hits", %{})
63 |> Map.get("hits", [])
64 |> Enum.map(fn result -> result["_id"] end)
65 |> Pleroma.Activity.all_by_ids_with_object()
66 |> Enum.filter(fn x -> Visibility.visible_for_user?(x, user) end)
72 StatusView.render("index.json",