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:
evazion
2022-09-01 17:49:35 -05:00
parent 2b76a4c5ba
commit e058cfba4d
2 changed files with 21 additions and 2 deletions

View 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