[#477] User trigram index adjustment.
authorIvan Tashkinov <ivantashkinov@gmail.com>
Fri, 18 Jan 2019 07:57:42 +0000 (10:57 +0300)
committerIvan Tashkinov <ivantashkinov@gmail.com>
Fri, 18 Jan 2019 07:57:42 +0000 (10:57 +0300)
lib/pleroma/user.ex
priv/repo/migrations/20190118074940_fix_user_trigram_index.exs [new file with mode: 0644]

index 1d0bf1edfd0f7ebaeb3ce787c1c47d0f6f620e91..eb4218ebee8d5d0f4900182d10fafb895829eeba 100644 (file)
@@ -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 (file)
index 0000000..4f7712e
--- /dev/null
@@ -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