1 package org.apache.lucene.search.highlight; 2 17 18 19 27 28 29 public class SpanGradientFormatter 30 extends GradientFormatter 31 { 32 public SpanGradientFormatter(float maxScore, String minForegroundColor, 33 String maxForegroundColor, String minBackgroundColor, 34 String maxBackgroundColor) 35 { 36 super( maxScore, minForegroundColor, 37 maxForegroundColor, minBackgroundColor, 38 maxBackgroundColor); 39 } 40 41 42 43 public String highlightTerm(String originalText, TokenGroup tokenGroup) 44 { 45 if (tokenGroup.getTotalScore() == 0) 46 return originalText; 47 float score = tokenGroup.getTotalScore(); 48 if (score == 0) 49 { 50 return originalText; 51 } 52 53 StringBuffer sb = new StringBuffer ( originalText.length() + EXTRA); 55 56 sb.append("<span style=\""); 57 if (highlightForeground) 58 { 59 sb.append("color: "); 60 sb.append(getForegroundColorString(score)); 61 sb.append("; "); 62 } 63 if (highlightBackground) 64 { 65 sb.append("background: "); 66 sb.append(getBackgroundColorString(score)); 67 sb.append("; "); 68 } 69 sb.append("\">"); 70 sb.append(originalText); 71 sb.append("</span>"); 72 return sb.toString(); 73 } 74 75 private static final String TEMPLATE = "<span style=\"background: #EEEEEE; color: #000000;\">...</span>"; 77 private static final int EXTRA = TEMPLATE.length(); 78 } 79 | Popular Tags |