Joe Wicentowski has added another excellent tutorial to the XQuery wikibook. It shows how to develop a keyword search on multiple document types and how to display search results with highlighted keywords in context (KWIC).
In particular the KWIC display should be interesting. It is based on XQuery code originally developed for the documentation search facility on the main eXist page and the wiki (see "Quick Search" box to the right). Contrary to earlier solutions, we no longer need complicated callback functions to extract the matches with surrounding text. Instead, all the processing is done in XQuery. This became possible thanks to recent improvements in the query engine (that's why you need an eXist version build from SVN).
Joe's tutorial guides you through a complete example. The XQuery wikibook is a great resource for XQuery in general. Don't miss it.