You can index a character that is modified with gin for search parameters. Try the following:
CREATE INDEX idx_post_tag ON posts USING GIN(tags); SELECT * FROM posts WHERE tags @> (ARRAY['search string'::character varying]);
This is when an exact match is required. If an exact match is undesirable, you should consider storing your tags as a text column. Think more about the meaning of these "tags." String array types do not have text indexing, stem support, and inflection, and therefore you cannot match things like Dance to Dance.
If this is not an option, you can work around this with a fixed version of the array_to_string function. Then your queries will be as follows:
CREATE INDEX posts_fts_idx ON posts USING gin(to_tsvector('english', immutable_array_to_string(tags, ' '))); SELECT "posts".* FROM "posts" WHERE (to_tsvector('english', immutable_array_to_string(tags, ' ')) @@ (to_tsquery('english', 'ruby')));
source share