January 2020
Intermediate to advanced
640 pages
16h 56m
English
Once we have generated a summary for a matched document, we need to identify and highlight all the search keywords that are present within it. For this task, we will create a helper type named matchHighlighter that constructs a set of regular expressions for matching each search keyword and wrap it with a special HTML tag that our frontend template renders using a highlighted style.
The frontend creates a single matchHighlighter instance for the entire set of results by invoking the newMatchHighlighter function, which is listed in the following code:
func newMatchHighlighter(searchTerms string) *matchHighlighter { var regexes []*regexp.Regexp for _, token := range strings.Fields(strings.Trim(searchTerms, `"` ...