ehatcher 2004/04/08 17:16:16 Added: contributions/hilighter/src/java/org/apache/lucene/search/highlight package.html Log: Initial addition of hit hilighting code contributed by Mark Harwood Revision Changes Path 1.1 jakarta-lucene-sandbox/contributions/hilighter/src/java/org/apache/lucene/search/highlight/package.html Index: package.html =================================================================== <html>
<body> The highlight package contains classes to provide "keyword in context" features typically used to highlight search terms in the text of results pages. <br> 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. <h2>Example Usage</h2> <pre> 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(this,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); } </pre> </body> </html> --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]