lucene-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ehatc...@apache.org
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
                        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: lucene-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: lucene-dev-help@jakarta.apache.org


Mime
View raw message