websearch_to_tsquery takes whatever the user typed
to_tsquery expects tsquery syntax, so a trailing & from a search box raises a syntax error. plainto_tsquery never raises but ANDs every word and throws away quotes and negation.
SELECT id, title FROM docs
WHERE search_vector @@ websearch_to_tsquery('english', $1)
ORDER BY ts_rank(search_vector, websearch_to_tsquery('english', $1)) DESC;websearch_to_tsquery, in Postgres since 11, parses what people already type: quoted phrases, or between terms, and -term to exclude. Bad input turns into a reasonable query instead of an exception.
postgresqlsearch