-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add tsvactor_column to store the tsvector - content in the database. This speeds up the search speed on large table, because these value isn't calculated on fly anymore. A dictionary configuration to allow to setup the used PostgreSQL dictionary.
- Loading branch information
1 parent
31d31d4
commit 23d9929
Showing
6 changed files
with
61 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
class AddSearchableContent < ActiveRecord::Migration[6.0] | ||
def up | ||
unless column_exists? :pg_search_documents, :searchable_content | ||
execute %|ALTER TABLE pg_search_documents | ||
ADD COLUMN searchable_content tsvector GENERATED ALWAYS AS ( | ||
to_tsvector('#{Alchemy::PgSearch.config[:dictionary]}', coalesce(content, '')) | ||
) STORED;| | ||
end | ||
end | ||
|
||
def down | ||
if column_exists? :pg_search_documents, :searchable_content | ||
remove_column :pg_search_documents, :searchable_content | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,7 @@ module Alchemy | |
module PgSearch | ||
module Config | ||
@@config = { | ||
dictionary: 'simple', | ||
paginate_per: 10 | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
spec/dummy/db/migrate/20231218165617_add_searchable_content.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
class AddSearchableContent < ActiveRecord::Migration[6.0] | ||
def up | ||
unless column_exists? :pg_search_documents, :searchable_content | ||
execute %|ALTER TABLE pg_search_documents | ||
ADD COLUMN searchable_content tsvector GENERATED ALWAYS AS ( | ||
to_tsvector('#{Alchemy::PgSearch.config[:dictionary]}', coalesce(content, '')) | ||
) STORED;| | ||
end | ||
end | ||
|
||
def down | ||
if column_exists? :pg_search_documents, :searchable_content | ||
remove_column :pg_search_documents, :searchable_content | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters