lucene-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
Subject cvs commit: jakarta-lucene-sandbox/contributions/hilighter/src/java/org/apache/lucene/search/highlight package.html
Date Fri, 09 Apr 2004 00:16:16 GMT
ehatcher    2004/04/08 17:16:16

  Added:       contributions/hilighter/src/java/org/apache/lucene/search/highlight
  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
  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>
  		IndexSearcher searcher = new IndexSearcher(ramDir);
  		Query query = QueryParser.parse("Kenne*", FIELD_NAME, analyzer);
  		query=query.rewrite(reader); //required to expand search terms
  		Hits hits =;
  		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,"...");

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message