Each document has several matches, some of them are exact, some of them are fuzzy. We define the result relevancy (and therefore the position) according to these matches.
Then we highlight the first matching word in the text and keep some context around. The idea is to highlight not the first match, but the first exact match, it’d give better impression.
Implementation note: this should be done for both the embedded docs and for the static website.