24 lines
1.6 KiB
SQL
24 lines
1.6 KiB
SQL
-- M15: pg_trgm extension + GIN trigram indexes for fuzzy/full-text search
|
|
-- Enables PostgreSQL trigram similarity search (pg_trgm) across conversations,
|
|
-- messages, contacts, and articles — supports fuzzy matching with relevance ranking.
|
|
-- Reference: Chatwoot GlobalSearchService — pg_trgm for fuzzy search on text columns.
|
|
|
|
-- Create pg_trgm extension (requires superuser; may need: CREATE EXTENSION IF NOT EXISTS pg_trgm WITH SCHEMA public;)
|
|
CREATE EXTENSION IF NOT EXISTS pg_trgm;
|
|
|
|
-- Conversations: trigram indexes on labels (for label search)
|
|
CREATE INDEX IF NOT EXISTS idx_conversations_labels_trgm ON conversations USING gin (labels gin_trgm_ops);
|
|
|
|
-- Messages: trigram indexes on content (primary search field)
|
|
CREATE INDEX IF NOT EXISTS idx_messages_content_trgm ON messages USING gin (content gin_trgm_ops);
|
|
|
|
-- Contacts: trigram indexes on name, email, phone_number, identifier
|
|
CREATE INDEX IF NOT EXISTS idx_contacts_name_trgm ON contacts USING gin (name gin_trgm_ops);
|
|
CREATE INDEX IF NOT EXISTS idx_contacts_email_trgm ON contacts USING gin (email gin_trgm_ops);
|
|
CREATE INDEX IF NOT EXISTS idx_contacts_phone_trgm ON contacts USING gin (phone_number gin_trgm_ops);
|
|
CREATE INDEX IF NOT EXISTS idx_contacts_identifier_trgm ON contacts USING gin (identifier gin_trgm_ops);
|
|
|
|
-- Articles: trigram indexes on title, description, content
|
|
CREATE INDEX IF NOT EXISTS idx_articles_title_trgm ON articles USING gin (title gin_trgm_ops);
|
|
CREATE INDEX IF NOT EXISTS idx_articles_description_trgm ON articles USING gin (description gin_trgm_ops);
|
|
CREATE INDEX IF NOT EXISTS idx_articles_content_trgm ON articles USING gin (content gin_trgm_ops); |