snippetsqlMinor
How to make middle and suffix matching using full text search?
Viewed 0 times
suffixfullsearchtextmakeusinghowandmiddlematching
Problem
I'm trying to find a string on a database using FTS on Postgres:
But the
I found this question Get partial match from Get partial match from GIN indexed
But it doesn't mention how to solve the problem of middle and suffix matching using FTS?
select name
from users
where to_tsvector('simple', name) @@ to_tsquery('simple', 'ad:*')But the
:* search only the words start with ad.I found this question Get partial match from Get partial match from GIN indexed
TSVECTOR column column.But it doesn't mention how to solve the problem of middle and suffix matching using FTS?
Solution
The "Full" in Full Text Search means match full words, not parts of words
You should use RegExp or LIKE or tri-gram matching instead
You can mimic suffix matching by reversing words in your index and also reversing your queries, but this takes more space:
You should use RegExp or LIKE or tri-gram matching instead
You can mimic suffix matching by reversing words in your index and also reversing your queries, but this takes more space:
select
reverse('brown fox')::tsvector @@ (reverse('rown') || ':*')::tsquery --trueCode Snippets
select
reverse('brown fox')::tsvector @@ (reverse('rown') || ':*')::tsquery --trueContext
StackExchange Database Administrators Q#189084, answer score: 7
Revisions (0)
No revisions yet.