Highlight-matching now works
Finished writing and doing basic testing of highlight-matching.xsl. The purpose of this file is to create supplement then normal way eXist tags
search hits. When single items are searched for using the normal eXist &= and
|= operators, each hit is tagged with an <exist:match> tag, This tag can then
be used in the output to highlight the hits. However, when we search for an
"exact phrase", we have to use the XPath contains() function in the XQuery.
In this situation, the hits are not highlighted, because eXist isn't using its tokenized
index. Therefore we need to keep track of the phrases which the user has
searched on (only those searched using the + or AND operators), and then
process each text node in the output to see if any of those phrases appear
in the node. If they do, we need to highlight them.
This is achieved by first harvesting the search phrases from the <teiHeader> of the
search results document, and putting them into a sequence called $phrasesToTag.
Then we match on each text() node, and (assuming there are any phrases to
highlight), we pass that node to a recursive template called tagMatches. This
checks each of the elements in $phrasesToHighlight against the text node, using
the contains() function; if it finds the phrase within the text node, it passes the
text node and the phrase to another recursive function called tagMatch, which
highlights all instances of that phrase.
The only limitation at the moment is that if there are multiple phrases, and more than one of them shows up in the same text node, only the first will be tagged. This is annoying, but it's not really a big deal; it's unlikely that multiple matches of phrases will show up often in the same text node, and in any case, the text node itself (or its ancestor node) will be returned as part of the hit report due to the first phrase being tagged in it, so we won't worry so much about this.
There's also probably room for some optimization in this code, but that will come later.