I removed the error from the code (my mistake entirely), and now the function nearly works. Still using the “swan of your heart” test, when I search for exact matches, I get the exact match from the bottom of my 700000 character page! Great. This exact phrase occurs in one other piece on the site, however, and the result that shows up for this page, which happens to come first, for some reason does not display the highlighted exact match (this other page is much shorter in length).
Is there any way to be sure all instances of an exact match get displayed and highlighted in the results?