summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHaelwenn <contact+git.pleroma.social@hacktivis.me>2021-08-28 15:54:37 +0000
committerHaelwenn <contact+git.pleroma.social@hacktivis.me>2021-08-28 15:54:37 +0000
commit018b0948defcc392aaf60101de775bd1e576d677 (patch)
tree422a526eabaa6cdc8dd510bd2fe1fdcfdbda9dac
parent84ec0fbeaadc8bdbce256212258a932530088346 (diff)
parenta80cb58ac1902fc3d86f82a3d2b0473140e36f0c (diff)
Merge branch 'from/develop/tusooa/2758-gin-index-search' into 'develop'
Make activity search properly use GIN indexes Closes #2758 See merge request pleroma/pleroma!3519
-rw-r--r--CHANGELOG.md1
-rw-r--r--lib/pleroma/activity/search.ex18
2 files changed, 17 insertions, 2 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 231cac990..ae6b7506b 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -17,6 +17,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
## Unreleased-patch
- Mastodon API: Activity Search fallbacks on status fetching after a DB Timeout/Error
+- Make activity search properly use GIN indexes
## 2.4.0 - 2021-08-xx
diff --git a/lib/pleroma/activity/search.ex b/lib/pleroma/activity/search.ex
index a5923519c..09671f621 100644
--- a/lib/pleroma/activity/search.ex
+++ b/lib/pleroma/activity/search.ex
@@ -65,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
)
@@ -76,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
)