org.apache.lucene.search.highlight

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Search Engine » lucene » org.apache.lucene.search.highlight 
org.apache.lucene.search.highlight
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, Formatter classes.

Example Usage

  //... Above, create documents with two fields, one with term vectors (tv) and one without (notv)
  IndexSearcher searcher = new IndexSearcher(directory);
  QueryParser parser = new QueryParser("notv", analyzer);
  Query query = parser.parse("million");
  //query = query.rewrite(reader); //required to expand search terms
  Hits hits = searcher.search(query);

  SimpleHTMLFormatter htmlFormatter = new SimpleHTMLFormatter();
  Highlighter highlighter = new Highlighter(htmlFormatter, new QueryScorer(query));
  for (int i = 0; i < 10; i++) {
    String text = hits.doc(i).get("notv");
    TokenStream tokenStream = TokenSources.getAnyTokenStream(searcher.getIndexReader(), hits.id(i), "notv", analyzer);
    TextFragment[] frag = highlighter.getBestTextFragments(tokenStream, text, false, 10);//highlighter.getBestFragments(tokenStream, text, 3, "...");
    for (int j = 0; j < frag.length; j++) {
      if ((frag[j] != null) && (frag[j].getScore() > 0)) {
        System.out.println((frag[j].toString()));
      }
    }
    //Term vector
    text = hits.doc(i).get("tv");
    tokenStream = TokenSources.getAnyTokenStream(searcher.getIndexReader(), hits.id(i), "tv", analyzer);
    frag = highlighter.getBestTextFragments(tokenStream, text, false, 10);
    for (int j = 0; j < frag.length; j++) {
      if ((frag[j] != null) && (frag[j].getScore() > 0)) {
        System.out.println((frag[j].toString()));
      }
    }
    System.out.println("-------------");
  }

New features 06/02/2005

This release adds options for encoding (thanks to Nicko Cadell). An "Encoder" implementation such as the new SimpleHTMLEncoder class can be passed to the highlighter to encode all those non-xhtml standard characters such as & into legal values. This simple class may not suffice for some languages - Commons Lang has an implementation that could be used: escapeHtml(String) in http://svn.apache.org/viewcvs.cgi/jakarta/commons/proper/lang/trunk/src/java/org/apache/commons/lang/StringEscapeUtils.java?rev=137958&view=markup

New features 22/12/2004

This release adds some new capabilities:
  1. Faster highlighting using Term vector support
  2. New formatting options to use color intensity to show informational value
  3. Options for better summarization by using term IDF scores to influence fragment selection

The highlighter takes a TokenStream as input. Until now these streams have typically been produced using an Analyzer but the new class TokenSources provides helper methods for obtaining TokenStreams from the new TermVector position support (see latest CVS version).

The new class GradientFormatter can use a scale of colors to highlight terms according to their score. A subtle use of color can help emphasise the reasons for matching (useful when doing "MoreLikeThis" queries and you want to see what the basis of the similarities are).

The QueryScorer class has a new constructor which can use an IndexReader to derive the IDF (inverse document frequency) for each term in order to influcence the score. This is useful for helping to extracting the most significant sections of a document and in supplying scores used by the new GradientFormatter to color significant words more strongly. The QueryScorer.getMaxWeight method is useful when passed to the GradientFormatter constructor to define the top score which is associated with the top color.

Java Source File NameTypeComment
DefaultEncoder.javaClass
Encoder.javaInterface Encodes original text.
Formatter.javaInterface Processes terms found in the original text, typically by applying some form of mark-up to highlight terms in HTML search results pages.
Fragmenter.javaInterface Implements the policy for breaking text into multiple fragments for consideration by the Highlighter class.
GradientFormatter.javaClass Formats text with different color intensity depending on the score of the term.
Highlighter.javaClass Class used to markup highlighted terms found in the best sections of a text, using configurable Fragmenter , Scorer , Formatter , Encoder and tokenizers.
HighlighterTest.javaClass JUnit Test for Highlighter class.
NullFragmenter.javaClassFragmenter implementation which does not fragment the text.
QueryScorer.javaClassScorer implementation which scores text fragments by the number of unique query terms found. This class uses the QueryTermExtractor class to process determine the query terms and their boosts to be used.
QueryTermExtractor.javaClass Utility class used to extract the terms used in a query, plus any weights. This class will not find terms for MultiTermQuery, RangeQuery and PrefixQuery classes so the caller must pass a rewritten query (see Query.rewrite) to obtain a list of expanded terms.
Scorer.javaInterface
SimpleFragmenter.javaClassFragmenter implementation which breaks text up into same-size fragments with no concerns over spotting sentence boundaries.
SimpleHTMLEncoder.javaClass
SimpleHTMLFormatter.javaClass
SpanGradientFormatter.javaClass Formats text with different color intensity depending on the score of the term using the span tag.
TextFragment.javaClass Low-level class used to record information about a section of a document with a score.
TokenGroup.javaClass
TokenSources.javaClass Hides implementation issues associated with obtaining a TokenStream for use with the higlighter - can obtain from TermFreqVectors with offsets and (optionally) positions or from Analyzer class reparsing the stored content.
WeightedTerm.javaClass
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.