-- Basic Text Matching SELECT 'a fat cat sat on a mat and ate a fat rat'::tsvector @@ 'cat & rat'::tsquery; SELECT 'fat & cow'::tsquery @@ 'a fat cat sat on a mat and ate a fat rat'::tsvector; SELECT to_tsvector('fat cats ate fat rats') @@ to_tsquery('fat & rat'); SELECT 'fat cats ate fat rats'::tsvector @@ to_tsquery('fat & rat'); CREATE TABLE tv_series ( id SERIAL PRIMARY KEY, title TEXT NOT NULL, description TEXT NOT NULL, creator TEXT NOT NULL ); INSERT INTO tv_series (id, title, description, creator) VALUES (1, 'Stranger Things', 'Set in the fictional town of Hawkins, Indiana in the 1980s, the first season focuses on the investigation into the disappearance of a young boy...', 'Duffer Brothers'), (2, 'Breaking Bad', 'BB is an American neo-western crime drama television series created and produced by Vince Gilligan. It tells the story of Walter White, a struggling high school chemistry teacher diagnosed with inoperable lung cancer...', 'Vince Gilligan'), (3, 'Band of Brothers', 'Band of Brothers is a 2001 American war drama miniseries based on historian Stephen E. Ambrose''s 1992 nonfiction book of the same name. The executive producers were Steven Spielberg and Tom Hanks...', 'Steven Spielberg, Tom Hanks'), (4, 'Rick and Morty', 'Rick and Morty is an American animated science-fiction sitcom created by Justin Roiland and Dan Harmon for Cartoon Network''s late-night programming block...', 'Justin Roiland, Dan Harmon'); SELECT (to_tsvector(title) || to_tsvector(description) || to_tsvector(creator)) AS document FROM tv_series; SELECT to_tsvector(description) @@ 'rick' FROM tv_series WHERE id = 4; SELECT to_tsvector(description) @@ 'morty' FROM tv_series WHERE id = 4; SELECT 'morty'::tsquery, to_tsquery('morty'); SELECT 'rick'::tsquery, to_tsquery('rick'); SELECT to_tsvector(description) @@ to_tsquery('morty') FROM tv_series WHERE id = 4; ALTER TABLE tv_series ADD "document_vectors" tsvector; CREATE INDEX idx_fts_doc_vec ON tv_series USING gin(document_vectors); UPDATE tv_series SET document_vectors = (to_tsvector(title) || to_tsvector(description) || to_tsvector(creator)); INSERT INTO tv_series (id, title, description, creator, document_vectors) VALUES (5, 'Better Call Saul', 'Better Call Saul is an American television crime drama series created by Vince Gilligan and Peter Gould. It is a spin-off prequel of Gilligan''s prior series Breaking Bad.', 'Vince Gilligan, Peter Gould', (to_tsvector('Better Call Saul') || to_tsvector('Better Call Saul is an American television crime drama series created by Vince Gilligan and Peter Gould. It is a spin-off prequel of Gilligan''s prior series Breaking Bad.') || to_tsvector('Vince Gilligan, Peter Gould'))); SELECT id, title, creator FROM tv_series WHERE document_vectors @@ to_tsquery('break');