You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by gb...@apache.org on 2013/05/02 19:11:27 UTC
svn commit: r1478450 -
/lucene/dev/trunk/solr/core/src/java/org/apache/solr/search/SolrCacheBase.java
Author: gbowyer
Date: Thu May 2 17:11:26 2013
New Revision: 1478450
URL: http://svn.apache.org/r1478450
Log:
SOLR-4616: Make HitRatio into a float in mbeans
Modified:
lucene/dev/trunk/solr/core/src/java/org/apache/solr/search/SolrCacheBase.java
Modified: lucene/dev/trunk/solr/core/src/java/org/apache/solr/search/SolrCacheBase.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/core/src/java/org/apache/solr/search/SolrCacheBase.java?rev=1478450&r1=1478449&r2=1478450&view=diff
==============================================================================
--- lucene/dev/trunk/solr/core/src/java/org/apache/solr/search/SolrCacheBase.java (original)
+++ lucene/dev/trunk/solr/core/src/java/org/apache/solr/search/SolrCacheBase.java Thu May 2 17:11:26 2013
@@ -18,6 +18,8 @@
package org.apache.solr.search;
import java.io.Serializable;
+import java.math.BigDecimal;
+import java.math.RoundingMode;
import java.net.URL;
import java.util.Map;
@@ -90,21 +92,13 @@ public abstract class SolrCacheBase {
* Returns a "Hit Ratio" (ie: max of 1.00, not a percentage) suitable for
* display purposes.
*/
- protected static String calcHitRatio(long lookups, long hits) {
- if (lookups==0) return "0.00";
- if (lookups==hits) return "1.00";
- int hundredths = (int)(hits*100/lookups); // rounded down
- if (hundredths < 10) return "0.0" + hundredths;
- return "0." + hundredths;
-
- /*** code to produce a percent, if we want it...
- int ones = (int)(hits*100 / lookups);
- int tenths = (int)(hits*1000 / lookups) - ones*10;
- return Integer.toString(ones) + '.' + tenths;
- ***/
+ protected static float calcHitRatio(long lookups, long hits) {
+ return (lookups == 0) ? 0.0f :
+ BigDecimal.valueOf((double) hits / (double) lookups)
+ .setScale(2, RoundingMode.HALF_EVEN)
+ .floatValue();
}
-
public String getVersion() {
return SolrCore.version;
}