summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergey Suprunenko <suprunenko.s@gmail.com>2020-03-31 19:10:10 +0200
committerSergey Suprunenko <suprunenko.s@gmail.com>2020-03-31 19:10:10 +0200
commit6650c69aafd786314204c6617d979393377a7bb7 (patch)
tree83dedf149b31dcb3d726eea5e6ac0479a13960e5
parent72ef8bc7b08540aed95466e3fce36a682fb00c7a (diff)
Add activity summary to RUM full text search
-rw-r--r--lib/pleroma/activity/search.ex6
-rw-r--r--priv/repo/optional_migrations/rum_indexing/20200327223848_add_summary_to_fts_index_two.exs48
2 files changed, 54 insertions, 0 deletions
diff --git a/lib/pleroma/activity/search.ex b/lib/pleroma/activity/search.ex
index 124b663b2..aea371102 100644
--- a/lib/pleroma/activity/search.ex
+++ b/lib/pleroma/activity/search.ex
@@ -75,6 +75,12 @@ defmodule Pleroma.Activity.Search do
o.fts_content,
^search_query
),
+ or_where:
+ fragment(
+ "? @@ plainto_tsquery('english', ?)",
+ o.fts_summary,
+ ^search_query
+ ),
order_by: [fragment("? <=> now()::date", o.inserted_at)]
)
end
diff --git a/priv/repo/optional_migrations/rum_indexing/20200327223848_add_summary_to_fts_index_two.exs b/priv/repo/optional_migrations/rum_indexing/20200327223848_add_summary_to_fts_index_two.exs
new file mode 100644
index 000000000..2dc3c5d09
--- /dev/null
+++ b/priv/repo/optional_migrations/rum_indexing/20200327223848_add_summary_to_fts_index_two.exs
@@ -0,0 +1,48 @@
+defmodule Pleroma.Repo.Migrations.AddSummaryToFtsIndexTwo do
+ use Ecto.Migration
+
+ def up do
+ drop_if_exists(
+ index(:objects, ["(to_tsvector('english', data->>'summary'))"],
+ using: :gin,
+ name: :objects_summary_fts
+ )
+ )
+
+ alter table(:objects) do
+ add(:fts_summary, :tsvector)
+ end
+
+ execute("""
+ CREATE OR REPLACE FUNCTION objects_fts_update() RETURNS trigger AS $$
+ begin
+ new.fts_summary := to_tsvector('english', new.data->>'summary');
+ new.fts_content := to_tsvector('english', new.data->>'content');
+ return new;
+ end
+ $$ LANGUAGE plpgsql
+ """)
+ end
+
+ def down do
+ alter table(:objects) do
+ remove(:fts_summary, :tsvector)
+ end
+
+ create_if_not_exists(
+ index(:objects, ["(to_tsvector('english', data->>'summary'))"],
+ using: :gin,
+ name: :objects_summary_fts
+ )
+ )
+
+ execute("""
+ CREATE OR REPLACE FUNCTION objects_fts_update() RETURNS trigger AS $$
+ begin
+ new.fts_content := to_tsvector('english', new.data->>'content');
+ return new;
+ end
+ $$ LANGUAGE plpgsql
+ """)
+ end
+end