fix: Added pg_trgm extension

This commit is contained in:
Tejaswini Chile 2022-12-13 10:12:57 +05:30
parent 4d2afface2
commit 5c322e96a4
4 changed files with 6 additions and 5 deletions

View file

@ -4,10 +4,9 @@ module MultiSearchableHelpers
included do included do
PgSearch.multisearch_options = { PgSearch.multisearch_options = {
using: { using: {
trigram: {},
tsearch: { tsearch: {
prefix: true, any_word: true
any_word: true,
normalization: 3
} }
} }
} }
@ -16,7 +15,7 @@ module MultiSearchableHelpers
return if contact_pg_search_record.present? return if contact_pg_search_record.present?
initialize_contact_pg_search_record.update!( initialize_contact_pg_search_record.update!(
content: "#{contact.id} #{contact.email} #{contact.name} #{contact.phone_number}", content: "#{contact.id} #{contact.email} #{contact.name} #{contact.phone_number} #{contact.account_id}",
conversation_id: id conversation_id: id
) )
end end

View file

@ -154,7 +154,7 @@ class Contact < ApplicationRecord
INSERT INTO pg_search_documents (searchable_type, searchable_id, content, account_id, conversation_id, created_at, updated_at) INSERT INTO pg_search_documents (searchable_type, searchable_id, content, account_id, conversation_id, created_at, updated_at)
SELECT 'Contact' AS searchable_type, SELECT 'Contact' AS searchable_type,
contacts.id AS searchable_id, contacts.id AS searchable_id,
CONCAT_WS(' ', contacts.email, contacts.name, contacts.phone_number, contacts.id, contacts.account_id) AS content, CONCAT_WS(' ', contacts.id, contacts.email, contacts.name, contacts.phone_number, contacts.account_id) AS content,
contacts.account_id::int AS account_id, contacts.account_id::int AS account_id,
conversations.id AS conversation_id, conversations.id AS conversation_id,
now() AS created_at, now() AS created_at,

View file

@ -3,6 +3,7 @@ class EnableMultiSearchable < ActiveRecord::Migration[6.1]
Contact.rebuild_pg_search_documents Contact.rebuild_pg_search_documents
PgSearch::Multisearch.rebuild(Conversation) PgSearch::Multisearch.rebuild(Conversation)
PgSearch::Multisearch.rebuild(Message) PgSearch::Multisearch.rebuild(Message)
execute 'create extension pg_trgm;'
end end
def down def down

View file

@ -14,6 +14,7 @@ ActiveRecord::Schema.define(version: 2022_12_12_061802) do
# These are extensions that must be enabled in order to support this database # These are extensions that must be enabled in order to support this database
enable_extension "pg_stat_statements" enable_extension "pg_stat_statements"
enable_extension "pg_trgm"
enable_extension "pgcrypto" enable_extension "pgcrypto"
enable_extension "plpgsql" enable_extension "plpgsql"