Skip to content

armgit / solr

Public Imported from GitHub
0

Apache Solr open-source search software

Chaned score to float and added QueryScorer.getMaxTermWeight (useful for callibrating GradientFormatter)

Mark Harwoodceb895e77251
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;
+ }
}