Search a Word document and highlight every hit
Hits painted on pages that are not in the DOM.
The obvious way to build a find box is to walk the DOM for a string. It is wrong here for three reasons: it cannot see the pages that are not mounted, it matches the list and page numbers the renderer computed rather than read, and what it produces is a DOM node — which cannot be stored, sent anywhere, or found again after a relayout.
The index is built from the model instead, so a hit on page four hundred is found now and painted when you reach it.
const search = await viewer.search();
const hits = search.find('invoice');
// Every hit is painted, including on pages that are not mounted:
// the index is built from the model, not from the DOM.
search.highlight(hits);