The highlight package contains classes to provide "keyword in context" features typically used to highlight search terms in the text of results pages.
The Highlighter class is the central component and can be used to extract the most interesting sections of a piece of text and highlight them, with the help of Fragmenter, FragmentScorer and Formatter classes.

Example Usage

		IndexSearcher searcher = new IndexSearcher(ramDir);
		Query query = QueryParser.parse("Kenne*", FIELD_NAME, analyzer);
		query=query.rewrite(reader); //required to expand search terms
		Hits hits = searcher.search(query);

		Highlighter highlighter =new Highlighter(new QueryScorer(query));
		for (int i = 0; i < hits.length(); i++)
		{
			String text = hits.doc(i).get(FIELD_NAME);
			TokenStream tokenStream=analyzer.tokenStream(FIELD_NAME,new StringReader(text));
			// Get 3 best fragments and seperate with a "..." 
			String result = highlighter.getBestFragments(tokenStream,text,3,"...");
			System.out.println(result);
		}