Here is an example plainto_tsquery
call in postgres 15.1:
# select plainto_tsquery('english', 'postgres is the best');
plainto_tsquery
-------------------
'postgr' & 'best'
(1 row)
This is the equivalent of
select to_tsquery('english', 'postgr & best');
to_tsquery
-------------------
'postgr' & 'best'
The docs say
plainto_tsquery transforms the unformatted text querytext to a tsquery value. The text is parsed and normalized much as for to_tsvector, then the & (AND) tsquery operator is inserted between surviving words.
How do I get the same result (parsed and normalized) from a text phrase, but with '|'
between the tokens, e.g., the equivalent of
# select to_tsquery('english', 'postgr | best');
to_tsquery
-------------------
'postgr' | 'best'
but being able to pass in "postgres is the best" as input?
2
Answers
I don’t know a direct way, but that many conversions isn’t goo for the performance
Alsopossible is it to make a string and thenmake a tsquery from it instead of a String
fiddle
Use
websearch_to_tsquery()
: