Finished first pass at contents.xq
Having decided, for the moment, to offload the heavy lifting of the search string parsing to Java code, I rewrote the contents.xq page so that it just does a simple |= job on the search string contents, so I can carry on working on the rest of the page. This seems to work fine. Next, we move on to the XSLT, which is going to be complicated too: it will have to find all the matches that were achieved with contains(), which will not be tagged up with <exist:match> tags, and either tag them up or highlight them in some other way. That means I really do need to know what the search string was, even at the XSLT level. Perhaps this tagging should take place in a preliminary XSLT operation, prior to the main rendering of the page.
Also, it strikes me that the Java class I'm writing ought also to be able to spit out a list of the phrases that will need highlighting, in a format that's easily parsed by XSLT. That would make things quicker and simpler.