Skip to content
IT glossary
DatabasesUpdated December 3, 2026

Full-text search

Полнотекстовый поиск

Full-text search finds documents by the words or phrases in their contents. Depending on how it is configured, it can match different forms of a word and rank the results by relevance.

Also known as: tsvector

What it does

Imagine searching a help center for reset password. An article titled “Resetting your password” should probably appear, even though the exact string is missing. Full-text search can match reset with resetting and find the two query terms even when other words come between them. A substring check such as LIKE '%reset password%' looks for that exact character sequence instead. That makes substring search useful for tasks like finding part of a product code, where treating the input as natural language can get in the way.

How it works

A text analyzer splits a document into tokens and applies language-specific rules. An English configuration might reduce resetting to reset and ignore common words such as your. Queries need compatible analysis so that their terms can match the terms stored for documents.

An inverted index maps each searchable term to the documents that contain it. To require two terms, the engine can intersect their document lists rather than read every document. Phrase search also checks word positions. Matching and ranking are separate steps: matching decides which documents qualify; ranking decides which to show first. A ranking function can, for example, reward a hit in the title more than a hit in the body.

A PostgreSQL example

In PostgreSQL, tsvector is the data type for a processed document, not another name for full-text search. It holds normalized terms called lexemes, optionally with positions and weights. A tsquery holds search conditions, and @@ tests whether a document satisfies them.

CREATE INDEX articles_body_fts ON articles
  USING GIN (to_tsvector('english', body));

SELECT id, title
FROM articles
WHERE to_tsvector('english', body)
   @@ plainto_tsquery('english', 'reset password');

This query searches the body, not the title. plainto_tsquery requires both resulting lexemes but does not require them to be adjacent or in query order. Use phraseto_tsquery when the phrase matters. The indexed expression matches the document expression in WHERE, and both sides use the English configuration. The GIN index can speed up filtering, but it does not return rows in relevance order. To rank results, add an explicit ORDER BY, for example using ts_rank in descending order.

Where to use it

Full-text search fits help centers, job listings, and product descriptions. PostgreSQL is a reasonable starting point when the content already lives there and search requirements are modest. A dedicated engine such as Elasticsearch is worth considering when you need different analyzers per field or want to scale search independently, but it adds a separate index to keep in sync. Normalizing words is not the same as fixing typos or matching synonyms; those features need their own configuration or search techniques.

In interviews

You may be asked to explain why an inverted index helps or why PostgreSQL might still scan a table that has a GIN index. If most rows match, reading the table sequentially can be cheaper than using the index and fetching the rows it points to. Use EXPLAIN (ANALYZE, BUFFERS) to check the plan on representative queries rather than assuming the index will always be used.