PostText/migrations/15/up.sql

28 lines
825 B
MySQL
Raw Normal View History

2023-10-27 18:34:17 +00:00
-- Fuzzy search
-- https://hevodata.com/blog/postgresql-full-text-search-setup/#Fuzzy_Search_vs_Full_Text_Search
CREATE EXTENSION pg_trgm;
-- Create column for seearch tokens
ALTER TABLE threads
2023-10-27 21:56:53 +00:00
ADD COLUMN search_tokens TSVECTOR
2023-10-27 18:34:17 +00:00
GENERATED ALWAYS AS
2023-10-27 21:56:53 +00:00
(TO_TSVECTOR('english', thread_author) ||
TO_TSVECTOR('english', thread_title ) ||
TO_TSVECTOR('english', thread_body )) STORED;
2023-10-27 18:34:17 +00:00
-- Create GIN index for search tokens
CREATE INDEX threads_search_idx
ON threads
USING GIN(search_tokens);
-- Same for remarks
ALTER TABLE remarks
2023-10-27 21:56:53 +00:00
ADD COLUMN search_tokens TSVECTOR
2023-10-27 18:34:17 +00:00
GENERATED ALWAYS AS
2023-10-27 21:56:53 +00:00
(TO_TSVECTOR('english', remark_author) ||
TO_TSVECTOR('english', remark_body )) STORED;
2023-10-27 18:34:17 +00:00
CREATE INDEX remarks_search_idx
ON remarks
USING GIN(search_tokens);