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
|
||||||
@@ -1896,7 +1896,8 @@ CREATE TABLE public.tags (
|
|||||||
created_at timestamp without time zone NOT NULL,
|
created_at timestamp without time zone NOT NULL,
|
||||||
updated_at timestamp without time zone NOT NULL,
|
updated_at timestamp without time zone NOT NULL,
|
||||||
is_locked boolean DEFAULT false NOT NULL,
|
is_locked boolean DEFAULT false NOT NULL,
|
||||||
is_deprecated boolean DEFAULT false NOT NULL
|
is_deprecated boolean DEFAULT false NOT NULL,
|
||||||
|
words character varying[] DEFAULT '{}'::character varying[] NOT NULL
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
@@ -4605,6 +4606,13 @@ CREATE INDEX index_tag_implications_on_consequent_name ON public.tag_implication
|
|||||||
CREATE INDEX index_tag_implications_on_forum_post_id ON public.tag_implications USING btree (forum_post_id);
|
CREATE INDEX index_tag_implications_on_forum_post_id ON public.tag_implications USING btree (forum_post_id);
|
||||||
|
|
||||||
|
|
||||||
|
--
|
||||||
|
-- Name: index_tags_on_array_to_tsvector_words; Type: INDEX; Schema: public; Owner: -
|
||||||
|
--
|
||||||
|
|
||||||
|
CREATE INDEX index_tags_on_array_to_tsvector_words ON public.tags USING gin (array_to_tsvector((words)::text[]));
|
||||||
|
|
||||||
|
|
||||||
--
|
--
|
||||||
-- Name: index_tags_on_is_deprecated; Type: INDEX; Schema: public; Owner: -
|
-- Name: index_tags_on_is_deprecated; Type: INDEX; Schema: public; Owner: -
|
||||||
--
|
--
|
||||||
@@ -5976,6 +5984,7 @@ INSERT INTO "schema_migrations" (version) VALUES
|
|||||||
('20220514175125'),
|
('20220514175125'),
|
||||||
('20220525214746'),
|
('20220525214746'),
|
||||||
('20220623052547'),
|
('20220623052547'),
|
||||||
('20220627211714');
|
('20220627211714'),
|
||||||
|
('20220829184824');
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user