liveBook · Manning

Followed by operator

As explained in Just Use Postgres!

The PostgreSQL full-text search distance operator requires one lexeme to occur a specified number of positions after another.

The PostgreSQL full-text search followed by operator requires one lexeme to occur a specified number of positions after another. Use it through to_tsquery when word order or distance matters, rather than merely requiring every term to appear. section 6.3.2

Match a three-position distance

SELECT id, name FROM omdb.movies WHERE lexemes @@ to_tsquery('return <3> king'); This query returns The Lord of the Rings: The Return of the King, matching “king” at the requested distance after “return.” The adjacent <-> form is also available for followed-by matching. section 6.3.2

How Just Use Postgres! covers it

How deep it goes
Defines positional matching and demonstrates numbered distance, without detailing full-text search internals.
Examples
Uses a movie query matching return <3> king and reports The Lord of the Rings: The Return of the King.
What it assumes
Assumes familiarity with PostgreSQL full-text search, lexemes, tsvector values, and to_tsquery.
What you can do after
Apply it via to_tsquery to filter indexed text by ordered lexemes separated by a specified number of positions.
How it connects
Connects to to_tsquery, tsvector, phrase search, and Boolean full-text operators.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Just Use Postgres!. The section links point to the parts of the book it draws on.