Question

Postgres full-text search returns nothing for partial words

Solved · 266 viewsasked by ines_data

Searching deploy finds deploying, but depl finds nothing.

What I’ve tried

Tried ilike '%depl%'. Works but slow at 100k rows.

Comment

2 answers

Marked as helpful by the asker
olu_backend

That's how full-text works: stems, not prefixes. For prefix search use to_tsquery('depl:*'), or combine full-text with pg_trgm and a GIN index on the text column for the 'as you type' case. This forum does exactly that: tsvector for ranked results, trigram as a fallback.

Comment
pawel_z

Numbers from a 120k-row table I had lying around, so you can see what the trigram index buys you for ilike:

create extension if not exists pg_trgm;
create index articles_body_trgm on articles using gin (body gin_trgm_ops);

Your existing ilike '%depl%' query uses it without changes. Needs at least 3 characters to be useful.

Comment
Same result here: 380 ms down to 9. Keeping full-text for ranking and the trigram index for type-ahead. ines_data