-
Notifications
You must be signed in to change notification settings - Fork 193
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add index to the title, details and instructions
This allows us to search the fields using MySQL’s fulltext search functions. Because we can’t index JSON fields using fulltext, we have to create a virtual column which casts the JSON as text. I tried some MySQL-fu to try and extract all the JSON values, but we can’t do it recursively. This should be enough anyway, as it’s what we’re only searching across the JSON at the moment.
- Loading branch information
Showing
2 changed files
with
20 additions
and
1 deletion.
There are no files selected for viewing
17 changes: 17 additions & 0 deletions
17
db/migrate/20250220131003_add_fulltext_index_to_content_block_editions.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,17 @@ | ||
class AddFulltextIndexToContentBlockEditions < ActiveRecord::Migration[8.0] | ||
INDEX_NAME = "title_details_instructions_to_publishers".freeze | ||
|
||
def up | ||
change_table :content_block_editions, bulk: true do |t| | ||
t.virtual :details_for_indexing, type: :text, as: "JSON_UNQUOTE(details)", stored: true | ||
t.index %i[title details_for_indexing instructions_to_publishers], name: INDEX_NAME, type: :fulltext | ||
end | ||
end | ||
|
||
def down | ||
change_table :content_block_editions, bulk: true do |t| | ||
t.remove :details_for_indexing | ||
end | ||
remove_index :content_block_editions, name: INDEX_NAME | ||
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