From 79e44042bc08cf69274008e408cac912ae693afe Mon Sep 17 00:00:00 2001 From: Ivan Tashkinov Date: Fri, 18 Jan 2019 10:57:42 +0300 Subject: [PATCH] [#477] User trigram index adjustment. --- lib/pleroma/user.ex | 2 +- .../20190118074940_fix_user_trigram_index.exs | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) create mode 100644 priv/repo/migrations/20190118074940_fix_user_trigram_index.exs diff --git a/lib/pleroma/user.ex b/lib/pleroma/user.ex index 1d0bf1edf..eb4218ebe 100644 --- a/lib/pleroma/user.ex +++ b/lib/pleroma/user.ex @@ -744,7 +744,7 @@ defp trigram_search_subquery(query) do select_merge: %{ search_rank: fragment( - "similarity(?, ? || ' ' || coalesce(?, ''))", + "similarity(?, trim(? || ' ' || coalesce(?, '')))", ^query, u.nickname, u.name diff --git a/priv/repo/migrations/20190118074940_fix_user_trigram_index.exs b/priv/repo/migrations/20190118074940_fix_user_trigram_index.exs new file mode 100644 index 000000000..4f7712eb0 --- /dev/null +++ b/priv/repo/migrations/20190118074940_fix_user_trigram_index.exs @@ -0,0 +1,13 @@ +defmodule Pleroma.Repo.Migrations.FixUserTrigramIndex do + use Ecto.Migration + + def up do + drop_if_exists index(:users, [], name: :users_trigram_index) + create index(:users, ["(trim(nickname || ' ' || name)) gist_trgm_ops"], name: :users_trigram_index, using: :gist) + end + + def down do + drop_if_exists index(:users, [], name: :users_trigram_index) + create index(:users, ["(nickname || name) gist_trgm_ops"], name: :users_trigram_index, using: :gist) + end +end