Refactor full-text search to get rid of tsvector columns.
Refactor full-text search on several tables (comments, dmails, forum_posts, forum_topics, notes, and wiki_pages) to use to_tsvector expression indexes instead of dedicated tsvector columns. This way full-text search works the same way across all tables. API changes: * Changed /wiki_pages.json?search[body_matches] to match against only the body. Before `body_matches` matched against both the title and the body. * Added /wiki_pages.json?search[title_or_body_matches] to match against both the title and the body. * Fixed /dmails.json?search[message_matches] to match against both the title and body when doing a wildcard search. Before a wildcard search only matched against the body. * Added /dmails.json?search[body_matches] to match against only the dmail body.
This commit is contained in:
28
db/migrate/20211015223510_add_tsvector_index_to_multiple.rb
Normal file
28
db/migrate/20211015223510_add_tsvector_index_to_multiple.rb
Normal file
@@ -0,0 +1,28 @@
|
||||
class AddTsvectorIndexToMultiple < ActiveRecord::Migration[6.1]
|
||||
disable_ddl_transaction!
|
||||
|
||||
def up
|
||||
add_index :comments, "to_tsvector('pg_catalog.english', body)", using: :gin, algorithm: :concurrently, name: "index_comments_on_body_tsvector"
|
||||
add_index :dmails, "(to_tsvector('pg_catalog.english', title) || to_tsvector('pg_catalog.english', body))", using: :gin, algorithm: :concurrently, name: "index_dmails_on_title_and_body_tsvector"
|
||||
add_index :forum_posts, "to_tsvector('pg_catalog.english', body)", using: :gin, algorithm: :concurrently, name: "index_forum_posts_on_body_tsvector"
|
||||
add_index :forum_topics, "to_tsvector('pg_catalog.english', title)", using: :gin, algorithm: :concurrently, name: "index_forum_topics_on_title_tsvector"
|
||||
add_index :notes, "to_tsvector('pg_catalog.english', body)", using: :gin, algorithm: :concurrently, name: "index_notes_on_body_tsvector"
|
||||
add_index :wiki_pages, "(to_tsvector('pg_catalog.english', title) || to_tsvector('pg_catalog.english', body))", using: :gin, algorithm: :concurrently, name: "index_wiki_pages_on_title_and_body_tsvector"
|
||||
|
||||
execute("VACUUM (VERBOSE, ANALYZE) comments")
|
||||
execute("VACUUM (VERBOSE, ANALYZE) dmails")
|
||||
execute("VACUUM (VERBOSE, ANALYZE) forum_posts")
|
||||
execute("VACUUM (VERBOSE, ANALYZE) forum_topics")
|
||||
execute("VACUUM (VERBOSE, ANALYZE) notes")
|
||||
execute("VACUUM (VERBOSE, ANALYZE) wiki_pages")
|
||||
end
|
||||
|
||||
def down
|
||||
remove_index :comments, algorithm: :concurrently, name: "index_comments_on_body_tsvector"
|
||||
remove_index :dmails, algorithm: :concurrently, name: "index_dmails_on_title_and_body_tsvector"
|
||||
remove_index :forum_posts, algorithm: :concurrently, name: "index_forum_posts_on_body_tsvector"
|
||||
remove_index :forum_topics, algorithm: :concurrently, name: "index_forum_topics_on_title_tsvector"
|
||||
remove_index :notes, algorithm: :concurrently, name: "index_notes_on_body_tsvector"
|
||||
remove_index :wiki_pages, algorithm: :concurrently, name: "index_wiki_pages_on_title_and_body_tsvector"
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user