I'm trying to utilize the full text search feature of PostgreSQL, particularly when user types in some search text, I would like to display him results with an assumption that the last word is incomplete.
For that purpose the "*" wildcard character needs to be attached to the last tsquery lexeme. E.g. if the user types in "The fat ra"
the tsquery should be 'fat' & 'ra':*
.
If I append the wildcard to the input string and parse it with plainto_tsquery
function then the wildcard is removed plainto_tsquery("The fat ra" || ":*") => 'fat' & 'ra'
.
Constructing a tsquery manually with to_tsquery
function requires a lot modifications to the string (such as trim spaces and other special characters, replace spaces with the ampersand character) to make the function accept it.
Is there an easier way to do that?
SELECT (phraseto_tsquery('')::text || ':*')::tsquery;
will raisesyntax error in tsquery: ":*"
. The same error will be raised if the query only contains stopwords likeSELECT (phraseto_tsquery('The and a')::text || ':*')::tsquery;
. – Fecundate