From ceb895e77251e30bc24a1bd8b724f6906a47ff6c Mon Sep 17 00:00:00 2001 From: Mark Harwood Date: Fri, 7 Jan 2005 21:17:09 +0000 Subject: [PATCH] Chaned score to float and added QueryScorer.getMaxTermWeight (useful for callibrating GradientFormatter) git-svn-id: https://svn.apache.org/repos/asf/lucene/java/trunk@151025 13f79535-47bb-0310-9956-ffa450edef68 --- .../lucene/search/highlight/GradientFormatter.java | 7 ++++--- .../apache/lucene/search/highlight/QueryScorer.java | 11 +++++++++++ 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/sandbox/contributions/highlighter/src/java/org/apache/lucene/search/highlight/GradientFormatter.java b/sandbox/contributions/highlighter/src/java/org/apache/lucene/search/highlight/GradientFormatter.java index 775e5c62747..680b0f87f17 100644 --- a/sandbox/contributions/highlighter/src/java/org/apache/lucene/search/highlight/GradientFormatter.java +++ b/sandbox/contributions/highlighter/src/java/org/apache/lucene/search/highlight/GradientFormatter.java @@ -23,7 +23,7 @@ package org.apache.lucene.search.highlight; */ public class GradientFormatter implements Formatter { - private int maxScore; + private float maxScore; int fgRMin, fgGMin, fgBMin; @@ -41,7 +41,8 @@ public class GradientFormatter implements Formatter * Sets the color range for the IDF scores * * @param maxScore - * The score (and above) displayed as maxColor + * The score (and above) displayed as maxColor (See QueryScorer.getMaxWeight + * which can be used to callibrate scoring scale) * @param minForegroundColor * The hex color used for representing IDF scores of zero eg * #FFFFFF (white) or null if no foreground color required @@ -55,7 +56,7 @@ public class GradientFormatter implements Formatter * The largest hex color used for representing IDF scores eg * #000000 (black) or null if no background color required */ - public GradientFormatter(int maxScore, String minForegroundColor, + public GradientFormatter(float maxScore, String minForegroundColor, String maxForegroundColor, String minBackgroundColor, String maxBackgroundColor) { diff --git a/sandbox/contributions/highlighter/src/java/org/apache/lucene/search/highlight/QueryScorer.java b/sandbox/contributions/highlighter/src/java/org/apache/lucene/search/highlight/QueryScorer.java index b425ad42572..040413435df 100644 --- a/sandbox/contributions/highlighter/src/java/org/apache/lucene/search/highlight/QueryScorer.java +++ b/sandbox/contributions/highlighter/src/java/org/apache/lucene/search/highlight/QueryScorer.java @@ -35,6 +35,7 @@ public class QueryScorer implements Scorer TextFragment currentTextFragment=null; HashSet uniqueTermsInFragment; float totalScore=0; + float maxTermWeight=0; private HashMap termsToFind; @@ -67,6 +68,7 @@ public class QueryScorer implements Scorer for (int i = 0; i < weightedTerms.length; i++) { termsToFind.put(weightedTerms[i].term,weightedTerms[i]); + maxTermWeight=Math.max(maxTermWeight,weightedTerms[i].getWeight()); } } @@ -122,4 +124,13 @@ public class QueryScorer implements Scorer //this class has no special operations to perform at end of processing } + /** + * + * @return The highest weighted term (useful for passing to GradientFormatter to set + * top end of coloring scale. + */ + public float getMaxTermWeight() + { + return maxTermWeight; + } }