summaryrefslogtreecommitdiff
path: root/lib/pleroma/activity/search.ex
diff options
context:
space:
mode:
Diffstat (limited to 'lib/pleroma/activity/search.ex')
-rw-r--r--lib/pleroma/activity/search.ex48
1 files changed, 33 insertions, 15 deletions
diff --git a/lib/pleroma/activity/search.ex b/lib/pleroma/activity/search.ex
index ed898ba4f..09671f621 100644
--- a/lib/pleroma/activity/search.ex
+++ b/lib/pleroma/activity/search.ex
@@ -26,19 +26,23 @@ defmodule Pleroma.Activity.Search do
:plain
end
- Activity
- |> Activity.with_preloaded_object()
- |> Activity.restrict_deactivated_users()
- |> restrict_public()
- |> query_with(index_type, search_query, search_function)
- |> maybe_restrict_local(user)
- |> maybe_restrict_author(author)
- |> maybe_restrict_blocked(user)
- |> Pagination.fetch_paginated(
- %{"offset" => offset, "limit" => limit, "skip_order" => index_type == :rum},
- :offset
- )
- |> maybe_fetch(user, search_query)
+ try do
+ Activity
+ |> Activity.with_preloaded_object()
+ |> Activity.restrict_deactivated_users()
+ |> restrict_public()
+ |> query_with(index_type, search_query, search_function)
+ |> maybe_restrict_local(user)
+ |> maybe_restrict_author(author)
+ |> maybe_restrict_blocked(user)
+ |> Pagination.fetch_paginated(
+ %{"offset" => offset, "limit" => limit, "skip_order" => index_type == :rum},
+ :offset
+ )
+ |> maybe_fetch(user, search_query)
+ rescue
+ _ -> maybe_fetch([], user, search_query)
+ end
end
def maybe_restrict_author(query, %User{} = author) do
@@ -61,10 +65,17 @@ defmodule Pleroma.Activity.Search do
end
defp query_with(q, :gin, search_query, :plain) do
+ %{rows: [[tsc]]} =
+ Ecto.Adapters.SQL.query!(
+ Pleroma.Repo,
+ "select current_setting('default_text_search_config')::regconfig::oid;"
+ )
+
from([a, o] in q,
where:
fragment(
- "to_tsvector(?->>'content') @@ plainto_tsquery(?)",
+ "to_tsvector(?::oid::regconfig, ?->>'content') @@ plainto_tsquery(?)",
+ ^tsc,
o.data,
^search_query
)
@@ -72,10 +83,17 @@ defmodule Pleroma.Activity.Search do
end
defp query_with(q, :gin, search_query, :websearch) do
+ %{rows: [[tsc]]} =
+ Ecto.Adapters.SQL.query!(
+ Pleroma.Repo,
+ "select current_setting('default_text_search_config')::regconfig::oid;"
+ )
+
from([a, o] in q,
where:
fragment(
- "to_tsvector(?->>'content') @@ websearch_to_tsquery(?)",
+ "to_tsvector(?::oid::regconfig, ?->>'content') @@ websearch_to_tsquery(?)",
+ ^tsc,
o.data,
^search_query
)