FileDocCategorySizeDatePackage
SpanGradientFormatter.javaAPI DocApache Lucene 1.92402Mon Feb 20 09:18:22 GMT 2006org.apache.lucene.search.highlight

SpanGradientFormatter

public class SpanGradientFormatter extends GradientFormatter
Formats text with different color intensity depending on the score of the term using the span tag. GradientFormatter uses a bgcolor argument to the font tag which doesn't work in Mozilla, thus this class.
see
GradientFormatter
author
David Spencer dave@searchmorph.com

Fields Summary
private static final String
TEMPLATE
private static final int
EXTRA
Constructors Summary
public SpanGradientFormatter(float maxScore, String minForegroundColor, String maxForegroundColor, String minBackgroundColor, String maxBackgroundColor)

		super( maxScore, minForegroundColor,
			   maxForegroundColor, minBackgroundColor,
			   maxBackgroundColor);
	
Methods Summary
public java.lang.StringhighlightTerm(java.lang.String originalText, TokenGroup tokenGroup)

        if (tokenGroup.getTotalScore() == 0)
            return originalText;
        float score = tokenGroup.getTotalScore();
        if (score == 0)
        {
            return originalText;
        }

		// try to size sb correctly
        StringBuffer sb = new StringBuffer( originalText.length() + EXTRA);
		
		sb.append("<span style=\""); 
		if (highlightForeground) 
		{
			sb.append("color: "); 
			sb.append(getForegroundColorString(score)); 
			sb.append("; "); 
		}
		if (highlightBackground)
		{
			sb.append("background: ");
			sb.append(getBackgroundColorString(score));
			sb.append("; ");
		}
		sb.append("\">");
		sb.append(originalText);
		sb.append("</span>");
        return sb.toString();