RefLib

Reference library for AI

Back

postgresql_16:3.9.1 Introduction

PostgreSQL 16 > The SQL Language > Full Text Search > Introduction

Full Text Searching (or just *text search*) provides the capability to identify natural-language *documents* that satisfy a *query*, and optionally to sort them by relevance to the query. The most common type of search is to find all documents containing given *query terms* and return them in order of their *similarity* to the query. Notions of query and similarity are very flexible and depend on the specific application. The simplest search considers query as a set of words and similarity as the frequency of query words in the document.

Textual search operators have existed in databases for years. PostgreSQL has ~, ~*, LIKE, and ILIKE operators for textual data types, but they lack many essential properties required by modern information systems:

Full text indexing allows documents to be *preprocessed* and an index saved for later rapid searching. Preprocessing includes:

Dictionaries allow fine-grained control over how tokens are normalized. With appropriate dictionaries, you can:

A data type tsvector is provided for storing preprocessed documents, along with a type tsquery for representing processed queries ((see postgresql_16:3.5.11)). There are many functions and operators available for these data types ((see postgresql_16:3.6.13)), the most important of which is the match operator @@, which we introduce in (see postgresql_16:3.9.1.2). Full text searches can be accelerated using indexes ((see postgresql_16:3.9.9)).

Subsections

Back