tags: add words column.
Add a `words` column to the tags table. This will be used for parsing
tags into words for word-based matching in autocomplete.
For example, "very_long_hair" can be parsed into ["very", "long", "hair"].
The `array_to_tsvector(words)` index is for performing wildcard
searches. It lets us do e.g
SELECT * FROM tags WHERE array_to_tsvector(words) @@ 'hand:* & hold:*'
to find tags containing the words "hand*" and "hold*".
This commit is contained in:
10
db/migrate/20220829184824_add_words_to_tags.rb
Normal file
10
db/migrate/20220829184824_add_words_to_tags.rb
Normal file
@@ -0,0 +1,10 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class AddWordsToTags < ActiveRecord::Migration[7.0]
|
||||
disable_ddl_transaction!
|
||||
|
||||
def change
|
||||
add_column :tags, :words, :string, null: false, array: true, default: [], if_not_exists: true
|
||||
add_index :tags, "array_to_tsvector(words)", using: :gin, if_not_exists: true, algorithm: :concurrently
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user