org.apache.lucene.search.highlight

Class GradientFormatter

Implemented Interfaces:
Formatter
Known Direct Subclasses:
SpanGradientFormatter

public class GradientFormatter
extends Object
implements Formatter

Formats text with different color intensity depending on the score of the term.
Author:
maharwood

Field Summary

protected boolean
highlightBackground
protected boolean
highlightForeground

Constructor Summary

GradientFormatter(float maxScore, String minForegroundColor, String maxForegroundColor, String minBackgroundColor, String maxBackgroundColor)
Sets the color range for the IDF scores

Method Summary

protected String
getBackgroundColorString(float score)
protected String
getForegroundColorString(float score)
static int
hexToInt(String hex)
Converts a hex string into an int.
String
highlightTerm(String originalText, TokenGroup tokenGroup)

Field Details

highlightBackground

protected boolean highlightBackground

highlightForeground

protected boolean highlightForeground

Constructor Details

GradientFormatter

public GradientFormatter(float maxScore,
                         String minForegroundColor,
                         String maxForegroundColor,
                         String minBackgroundColor,
                         String maxBackgroundColor)
Sets the color range for the IDF scores
Parameters:
maxScore - The score (and above) displayed as maxColor (See QueryScorer.getMaxWeight which can be used to callibrate scoring scale)
minForegroundColor - The hex color used for representing IDF scores of zero eg #FFFFFF (white) or null if no foreground color required
maxForegroundColor - The largest hex color used for representing IDF scores eg #000000 (black) or null if no foreground color required
minBackgroundColor - The hex color used for representing IDF scores of zero eg #FFFFFF (white) or null if no background color required
maxBackgroundColor - The largest hex color used for representing IDF scores eg #000000 (black) or null if no background color required

Method Details

getBackgroundColorString

protected String getBackgroundColorString(float score)

getForegroundColorString

protected String getForegroundColorString(float score)

hexToInt

public static final int hexToInt(String hex)
Converts a hex string into an int. Integer.parseInt(hex, 16) assumes the input is nonnegative unless there is a preceding minus sign. This method reads the input as twos complement instead, so if the input is 8 bytes long, it will correctly restore a negative int produced by Integer.toHexString() but not neccesarily one produced by Integer.toString(x,16) since that method will produce a string like '-FF' for negative integer values.
Parameters:
hex - A string in capital or lower case hex, of no more then 16 characters.

highlightTerm

public String highlightTerm(String originalText,
                            TokenGroup tokenGroup)
Specified by:
highlightTerm in interface Formatter
Parameters:
originalText - The section of text being considered for markup
tokenGroup - contains one or several overlapping Tokens along with their scores and positions.

Copyright © 2000-2007 Apache Software Foundation. All Rights Reserved.