How can I generate a contextual sample with search terms highlighted to display for each document found like Google and some other search engines do?
At present, nothing supplied with the Xapian libraries or utilities can do this. It has been discussed a number of times, but no good solution was ever devised. One such discussion can be found here: http://article.gmane.org/gmane.comp.search.xapian.general/2027/match=context.
It should be obvious that this cannot be something done at indexing time since it's not known then what the search terms will be. If stemming is off, then you may be able to used the positional information in the database to construct groups of words around a term, however due to the fact punctuation and capitalization is not stored, the output isn't very attractive. See http://article.gmane.org/gmane.comp.search.xapian.general/2187/match=context.
One practical way of achieving this appears to be a solution based on the Search::Tools::HiLiter and Search::Tools::Snipper Perl modules but it's not a perfect solution. Phrase matching and highlighting seems to be troublesome. However if you can live with only highlighting single words it will work.
This solution does require that the original document be available for parsing at search time, but that's often not a problem.
