Created
December 16, 2020 09:50
-
-
Save lenolib/cf2a65bc99ad639eb207edc73cd0bac6 to your computer and use it in GitHub Desktop.
postgresql full text search schema
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ALTER TABLE my_table ADD COLUMN tsdoc tsvector; | |
CREATE INDEX my_table_tsvec_idx ON my_table USING GIN (customer_id, tsdoc); | |
-- Full text search for datafield specs | |
CREATE FUNCTION my_table_tsvec_trigger() RETURNS trigger AS $$ | |
BEGIN | |
NEW.tsdoc := | |
setweight(to_tsvector('simple', coalesce(NEW.name,'')), 'A') || | |
setweight(to_tsvector('simple', coalesce(NEW.description,'')), 'B'); | |
return NEW; | |
END | |
$$ LANGUAGE plpgsql; | |
CREATE TRIGGER my_table_tsvec_update BEFORE INSERT OR UPDATE | |
ON my_table FOR EACH ROW EXECUTE PROCEDURE my_table_tsvec_trigger(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment