Potion/internal/infrastructure/database/migrations/004_create_fts_index.sql
Hayden Hargreaves 3c5109c7d0 (DB/FEAT): Implemented full text search vector for database searching!
This is a HUGE upgrade and can mark the searching nearly complete! Other
than the scrolling and some other smaller UI things. The search appears
to be working.
2025-07-10 19:54:21 -07:00

18 lines
525 B
PL/PgSQL

-- Author: Hayden Hargreaves (hhargreaves2006@gmail.com)
-- Desc: Create a full text index on the recipes table.
-- Date: 07/10/2025
BEGIN;
-- Update recipes table with the search vector column
ALTER TABLE Recipes
ADD search_vector tsvector GENERATED ALWAYS AS (
setweight(to_tsvector('english', coalesce(title, '')), 'A') ||
setweight(to_tsvector('english', coalesce(description, '')), 'B')
) STORED;
-- Create the search index
CREATE INDEX idx_recipe_search_vector ON recipes USING GIN (search_vector);
COMMIT;