A character trigram is a sequence of three consecutive characters, including characters representing word boundaries. Comparing shared trigrams gives search systems a practical way to find approximate matches when exact words differ. section 10.3.1
Recovering a misspelled search
Someone searching for “Steven King” may miss results about “Stephen King” in an exact word index. A character-trigram index can share enough fragments between the spellings to retrieve and rank the relevant documents. section 10.3.1
Build a useful trigram representation by applying consistent tokenization rules:
- Extract three-character windows from each word, adding boundary trigrams such as “ tr” and “am ” for “trigram.” section 10.3.1
- Fold punctuation and whitespace into one boundary character so every tokenization step represents boundaries consistently. section 10.3.1
- Configure TfidfVectorizer with character analysis and a trigram ngram_range when indexing text for typo-tolerant search. section 3.9
