Add activity summary to GIN full text search
This commit is contained in:
parent
8bd5ad8664
commit
72ef8bc7b0
@ -54,7 +54,13 @@ defmodule Pleroma.Activity.Search do
|
||||
from([a, o] in q,
|
||||
where:
|
||||
fragment(
|
||||
"to_tsvector('english', ?->>'content') @@ plainto_tsquery('english', ?)",
|
||||
"(to_tsvector('english', ?->>'summary') @@ plainto_tsquery('english', ?))",
|
||||
o.data,
|
||||
^search_query
|
||||
),
|
||||
or_where:
|
||||
fragment(
|
||||
"(to_tsvector('english', ?->>'content') @@ plainto_tsquery('english', ?))",
|
||||
o.data,
|
||||
^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
|
@ -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