For word suggestion when do search.

I can query like

select title from test where ts_filter(tsv, '{A}') @@ to_tsquery('english_nostop', 'god<->o' || ':*')

# tsv is something like to_tsvector('english_nostop', test.title)

The <-> was something like pattern = pattern.replace(' ', '<->'). That may have some problem when pattern contain <. Thought we can remove such char.

Combine tsquery don't work here. I can't find away to do to_tsquery(':*')

But how to use phraseto_tsquery to replace to_tsquery ? And still can have :* work?

After @Laurenz Albe answer. phraseto_tsquery can't do this.

May be I need give more detail. Why I want to use phraseto_tsquery.

I use the

    Template = snowball
    , Language = english

CREATE TEXT SEARCH CONFIGURATION public.english_nostop ( COPY = pg_catalog.english );
ALTER MAPPING FOR asciiword, asciihword, hword_asciipart, hword, hword_part, word WITH english_stem_nostop;

To keep stop words can be searched.

But I need to change pattern like this in python:

pattern = info["pattern"]
replace_punctuation = str.maketrans(string.punctuation, ' ' * len(string.punctuation))
pattern = pattern.translate(replace_punctuation)
replace_space = pattern.replace(" ", '<->')

You can see I replace punctuation by ' '. Then replace ' ' with <->.

I came up this question. Because I wonder can I don't transform pattern in python and just use psql to transform pattern.

Why need both ':*' and <->. here is a example:

select title from book where ts_filter(tsv_nostop, '{A}') @@ to_tsquery('english_nostop', 'how<->t'||':*')
select title from book where ts_filter(tsv_nostop, '{A}') @@ to_tsquery('english_nostop', 'how<->t');

This will show title contain how to. When user input how t. We want pop up some title.

  • I think that using stemming but then adding :* doesn't make a whole lot of sense.
    – jjanes
    Jul 8, 2020 at 17:29
  • Can you show complete examples of what you want to start with and what you want to end with? What was the starting point that you want to lead to 'god' <-> 'o':*?
    – jjanes
    Jul 8, 2020 at 17:30

1 Answer 1


You cannot do that with phraseto_tsquery.

The lower-level functions provide more features that you cannot get with phraseto_tsquery or websearch_to_tsquery.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.