websearch_to_tsquery()

A function converting search engine-style queries to tsquery

websearch_to_tsquery() is a system function providing a flexible conversion from search engine-style queries to the tsquery type for use in full text searches.

websearch_to_tsquery() was added in PostgreSQL 11.

Usage

websearch_to_tsquery ( [ config regconfig, ] query text ) → tsquery

Quoted word sequences are converted to phrase tests. The word “or” is understood as producing an OR operator, and a dash produces a NOT operator; other punctuation is ignored.

Change history

Examples

Basic usage example for websearch_to_tsquery():

postgres=# SELECT websearch_to_tsquery('foo or bar -baz');
  websearch_to_tsquery  
------------------------
 'foo' | 'bar' & !'baz'
(1 row)

Categories

Full Text Search, System function

See also

to_tsquery(), plainto_tsquery(), phraseto_tsquery()