PostgreSQL has a built-in full-text search engine that eliminates the need for external tools like Elasticsearch for many use cases. Core Concepts tsvector — A document transformed into a sorted list of lexemes (normalized words). tsquery — A search query with boolean operators (& AND, OR, ! NOT). totsvector(config, text) — Converts text to a tsvector with language-aware stemming. totsquery(config, text) — Converts text to a tsquery. @@ — The match operator: tsvector @@ tsquery. Search Configurations PostgreSQL provides locale-aware configurations: english, french, german, etc. These handle stemming (running → run), stop words (the, is, a), and normalization. Ranking Use tsrank() or tsrankcd() to score results by relevance. Higher weight can be assigned to titles vs. body content using…
Key Takeaways
tsvector + tsquery + @@ operator provide built-in full-text search.
setweight() assigns relevance priority (A highest, D lowest) to different fields.
pgtrgm extension enables fuzzy/similarity search with trigrams.
GIN index on tsvector makes full-text search fast even on millions of rows.