Using Trigrams with FTS
In this section, you’ll work with trigrams, which are another way to search text. To do that, you’ll use the pg_trgm[418] extension mentioned (and enabled) earlier.
If you’re not familiar with trigrams, let’s cover what they are.
Words are made up of sequences of letters. These sequences are called n-grams[419] in the field of Natural Language Processing (NLP). N-grams are sequences without a specified length. An n-gram with a length of one is a unigram, two is a bigram, and three is (drumroll, please) a trigram.
When two words have many overlapping trigrams, they tend to be very similar. Consider the example of misspellings. A misspelled word will usually be very similar to the target word, sometimes off by a single ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access