ALTER TABLE media_items
ADD COLUMN IF NOT EXISTS search_vector tsvector GENERATED ALWAYS AS (
  setweight(to_tsvector('english', COALESCE(title, '')), 'A') || setweight(to_tsvector('english', COALESCE(artist, '')), 'B') || setweight(to_tsvector('english', COALESCE(album, '')), 'B') || setweight(to_tsvector('english', COALESCE(genre, '')), 'C') || setweight(
    to_tsvector('english', COALESCE(description, '')),
    'C'
  ) || setweight(
    to_tsvector('english', COALESCE(file_name, '')),
    'D'
  )
) STORED;

CREATE INDEX IF NOT EXISTS idx_media_search ON media_items USING GIN (search_vector);
