Add activity summary to RUM full text search

This commit is contained in:
Sergey Suprunenko 2020-03-31 19:10:10 +02:00
parent 72ef8bc7b0
commit 6650c69aaf
No known key found for this signature in database
GPG Key ID: 5DCA7D1BE3914F9C
2 changed files with 54 additions and 0 deletions

View File

@ -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

View File

@ -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