Class GradientFormatter
- java.lang.Object
-
- org.apache.lucene.search.highlight.GradientFormatter
-
- All Implemented Interfaces:
Formatter
- Direct Known Subclasses:
SpanGradientFormatter
public class GradientFormatter extends java.lang.Object implements Formatter
Formats text with different color intensity depending on the score of the term.
-
-
Field Summary
Fields Modifier and Type Field Description (package private) intbgBMax(package private) intbgBMin(package private) intbgGMax(package private) intbgGMin(package private) intbgRMax(package private) intbgRMin(package private) intfgBMax(package private) intfgBMin(package private) intfgGMax(package private) intfgGMin(package private) intfgRMax(package private) intfgRMinprivate static char[]hexDigitsprotected booleanhighlightBackgroundprotected booleanhighlightForegroundprivate floatmaxScore
-
Constructor Summary
Constructors Constructor Description GradientFormatter(float maxScore, java.lang.String minForegroundColor, java.lang.String maxForegroundColor, java.lang.String minBackgroundColor, java.lang.String maxBackgroundColor)Sets the color range for the IDF scores
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected java.lang.StringgetBackgroundColorString(float score)private intgetColorVal(int colorMin, int colorMax, float score)protected java.lang.StringgetForegroundColorString(float score)static inthexToInt(java.lang.String hex)Converts a hex string into an int.java.lang.StringhighlightTerm(java.lang.String originalText, TokenGroup tokenGroup)private static java.lang.StringintToHex(int i)
-
-
-
Field Detail
-
maxScore
private float maxScore
-
fgRMin
int fgRMin
-
fgGMin
int fgGMin
-
fgBMin
int fgBMin
-
fgRMax
int fgRMax
-
fgGMax
int fgGMax
-
fgBMax
int fgBMax
-
highlightForeground
protected boolean highlightForeground
-
bgRMin
int bgRMin
-
bgGMin
int bgGMin
-
bgBMin
int bgBMin
-
bgRMax
int bgRMax
-
bgGMax
int bgGMax
-
bgBMax
int bgBMax
-
highlightBackground
protected boolean highlightBackground
-
hexDigits
private static char[] hexDigits
-
-
Constructor Detail
-
GradientFormatter
public GradientFormatter(float maxScore, java.lang.String minForegroundColor, java.lang.String maxForegroundColor, java.lang.String minBackgroundColor, java.lang.String maxBackgroundColor)Sets the color range for the IDF scores- Parameters:
maxScore- The score (and above) displayed as maxColor (SeeQueryScorer.getMaxTermWeight()which can be used to calibrate scoring scale)minForegroundColor- The hex color used for representing IDF scores of zero eg #FFFFFF (white) or null if no foreground color requiredmaxForegroundColor- The largest hex color used for representing IDF scores eg #000000 (black) or null if no foreground color requiredminBackgroundColor- The hex color used for representing IDF scores of zero eg #FFFFFF (white) or null if no background color requiredmaxBackgroundColor- The largest hex color used for representing IDF scores eg #000000 (black) or null if no background color required
-
-
Method Detail
-
highlightTerm
public java.lang.String highlightTerm(java.lang.String originalText, TokenGroup tokenGroup)- Specified by:
highlightTermin interfaceFormatter- Parameters:
originalText- The section of text being considered for markuptokenGroup- contains one or several overlapping Tokens along with their scores and positions.
-
getForegroundColorString
protected java.lang.String getForegroundColorString(float score)
-
getBackgroundColorString
protected java.lang.String getBackgroundColorString(float score)
-
getColorVal
private int getColorVal(int colorMin, int colorMax, float score)
-
intToHex
private static java.lang.String intToHex(int i)
-
hexToInt
public static final int hexToInt(java.lang.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 necessarily 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.- Throws:
java.lang.NumberFormatException- if the string is more than 16 characters long, or if any character is not in the set [0-9a-fA-f]
-
-