From 9bfa86d16279aca5cab02b0f835540cb3ae3e824 Mon Sep 17 00:00:00 2001
From: phiresky <phireskyde+git@gmail.com>
Date: Thu, 27 Jul 2023 12:11:00 +0200
Subject: [PATCH] add trigram index to search (#3719)

* add trigram index to search

* add community index
---
 migrations/2023-07-24-232635_trigram-index/down.sql |  8 ++++++++
 migrations/2023-07-24-232635_trigram-index/up.sql   | 10 ++++++++++
 2 files changed, 18 insertions(+)
 create mode 100644 migrations/2023-07-24-232635_trigram-index/down.sql
 create mode 100644 migrations/2023-07-24-232635_trigram-index/up.sql

diff --git a/migrations/2023-07-24-232635_trigram-index/down.sql b/migrations/2023-07-24-232635_trigram-index/down.sql
new file mode 100644
index 00000000..6883178f
--- /dev/null
+++ b/migrations/2023-07-24-232635_trigram-index/down.sql
@@ -0,0 +1,8 @@
+DROP INDEX idx_comment_content_trigram;
+
+DROP INDEX idx_post_trigram;
+
+DROP INDEX idx_person_trigram;
+
+DROP INDEX idx_community_trigram;
+
diff --git a/migrations/2023-07-24-232635_trigram-index/up.sql b/migrations/2023-07-24-232635_trigram-index/up.sql
new file mode 100644
index 00000000..ed648b6e
--- /dev/null
+++ b/migrations/2023-07-24-232635_trigram-index/up.sql
@@ -0,0 +1,10 @@
+CREATE EXTENSION IF NOT EXISTS pg_trgm;
+
+CREATE INDEX IF NOT EXISTS idx_comment_content_trigram ON comment USING gin(content gin_trgm_ops);
+
+CREATE INDEX IF NOT EXISTS idx_post_trigram ON post USING gin(name gin_trgm_ops, body gin_trgm_ops);
+
+CREATE INDEX IF NOT EXISTS idx_person_trigram ON person USING gin(name gin_trgm_ops, display_name gin_trgm_ops);
+
+CREATE INDEX IF NOT EXISTS idx_community_trigram ON community USING gin(name gin_trgm_ops, title gin_trgm_ops);
+
-- 
2.44.1