Alex Klibisz
Alex Klibisz

Reputation: 1323

Postgres full-text search: make a tsvector by splitting on whitespace or by providing an array of tokens

I have a text search problem where I need to search systematically-generated text, i.e. not human-written natural language text.

The typical ts_tovector('english', 'foo bar baz') is not particularly helpful. In some cases it generates tokens which I know will be lead to false-positive search results.

Instead I'd really just like to either provide the tokens in a string where each token is separated by whitespace, or provide an array of ordered tokens.

For example, something along the lines of to_tsvector(array["foo", "bar", "baz"]) should produce three tokens: foo, bar, and baz. This seems like a pretty basic thing, but so far I haven't found any explicit documentation of this functionality.

Upvotes: 0

Views: 1058

Answers (1)

Laurenz Albe
Laurenz Albe

Reputation: 246308

This is indeed a basic thing, and all you have to do is use the simple text search configuration:

to_tsvector('simple', 'foo bar baz')

Upvotes: 2

Related Questions