From: Ivan Tashkinov Date: Fri, 18 Jan 2019 07:57:42 +0000 (+0300) Subject: [#477] User trigram index adjustment. X-Git-Url: https://git.squeep.com/?a=commitdiff_plain;h=79e44042bc08cf69274008e408cac912ae693afe;p=akkoma [#477] User trigram index adjustment. --- 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 @@ defmodule Pleroma.User 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