How to implement efficient search-as-you-type in postgres using edge n-grams

Viewed 109

I want to implement search-as-you-type functionality into my postgres database. I believe this requires n-grams, to be able to match an incomplete word to a longer string.

I have looked at the edge n-gram tokenizer from elasticsearch. This tokenizes phrases into n-grams. For example:

'2 Quick Foxes.' => [ Qu, Qui, Quic, Quick, Fo, Fox, Foxe, Foxes ]

I am using this to get equivalent functionality in postgres.

I am now wondering how I can efficiently query over a database containing rows of these edge n-grams, with a query such as "Quick Fo".

0 Answers
Related