Compare commits
3 Commits
feature/sa
...
feature/ad
Author | SHA1 | Date | |
---|---|---|---|
|
e7048471e0 | ||
|
6650c69aaf | ||
|
72ef8bc7b0 |
@ -54,6 +54,11 @@ defmodule Pleroma.Activity.Search do
|
||||
from([a, o] in q,
|
||||
where:
|
||||
fragment(
|
||||
"to_tsvector('english', ?->>'summary') @@ plainto_tsquery('english', ?)",
|
||||
o.data,
|
||||
^search_query
|
||||
) or
|
||||
fragment(
|
||||
"to_tsvector('english', ?->>'content') @@ plainto_tsquery('english', ?)",
|
||||
o.data,
|
||||
^search_query
|
||||
@ -66,6 +71,11 @@ defmodule Pleroma.Activity.Search do
|
||||
where:
|
||||
fragment(
|
||||
"? @@ plainto_tsquery('english', ?)",
|
||||
o.fts_summary,
|
||||
^search_query
|
||||
) or
|
||||
fragment(
|
||||
"? @@ plainto_tsquery('english', ?)",
|
||||
o.fts_content,
|
||||
^search_query
|
||||
),
|
||||
|
@ -0,0 +1,12 @@
|
||||
defmodule Pleroma.Repo.Migrations.AddSummaryToFtsIndex do
|
||||
use Ecto.Migration
|
||||
|
||||
def change do
|
||||
create_if_not_exists(
|
||||
index(:objects, ["(to_tsvector('english', data->>'summary'))"],
|
||||
using: :gin,
|
||||
name: :objects_summary_fts
|
||||
)
|
||||
)
|
||||
end
|
||||
end
|
@ -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
|
@ -37,6 +37,28 @@ defmodule Pleroma.Web.MastodonAPI.SearchControllerTest do
|
||||
end
|
||||
end
|
||||
|
||||
test "activity search", %{conn: conn} do
|
||||
user = insert(:user)
|
||||
|
||||
{:ok, activity} = CommonAPI.post(user, %{"status" => "Query in the body 2hu"})
|
||||
|
||||
{:ok, activity_two} =
|
||||
CommonAPI.post(user, %{"spoiler_text" => "2hu", "status" => "Query in the subject"})
|
||||
|
||||
{:ok, _activity} = CommonAPI.post(user, %{"status" => "No query"})
|
||||
|
||||
statuses =
|
||||
conn
|
||||
|> get("/api/v2/search", %{"q" => "2hu"})
|
||||
|> json_response(200)
|
||||
|> Map.get("statuses")
|
||||
|> Enum.map(& &1["id"])
|
||||
|
||||
assert length(statuses) == 2
|
||||
assert activity.id in statuses
|
||||
assert activity_two.id in statuses
|
||||
end
|
||||
|
||||
test "search", %{conn: conn} do
|
||||
user = insert(:user)
|
||||
user_two = insert(:user, %{nickname: "shp@shitposter.club"})
|
||||
|
Loading…
Reference in New Issue
Block a user