You are viewing a plain text version of this content. The canonical link for it is here.
Posted to solr-commits@lucene.apache.org by ho...@apache.org on 2009/04/08 01:31:12 UTC

svn commit: r763032 - in /lucene/solr/trunk: CHANGES.txt src/java/org/apache/solr/handler/admin/LukeRequestHandler.java src/test/org/apache/solr/handler/admin/LukeRequestHandlerTest.java

Author: hossman
Date: Tue Apr  7 23:31:12 2009
New Revision: 763032

URL: http://svn.apache.org/viewvc?rev=763032&view=rev
Log:
SOLR-1104: Fix some rounding errors in LukeRequestHandler's histogram

Added:
    lucene/solr/trunk/src/test/org/apache/solr/handler/admin/LukeRequestHandlerTest.java   (with props)
Modified:
    lucene/solr/trunk/CHANGES.txt
    lucene/solr/trunk/src/java/org/apache/solr/handler/admin/LukeRequestHandler.java

Modified: lucene/solr/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/lucene/solr/trunk/CHANGES.txt?rev=763032&r1=763031&r2=763032&view=diff
==============================================================================
--- lucene/solr/trunk/CHANGES.txt (original)
+++ lucene/solr/trunk/CHANGES.txt Tue Apr  7 23:31:12 2009
@@ -316,7 +316,8 @@
 35. SOLR-1072: absolute paths used in sharedLib attribute were
     incorrectly treated as relative paths. (hossman)
 
-
+36. SOLR-1104: Fix some rounding errors in LukeRequestHandler's histogram (hossman)
+    
 Other Changes
 ----------------------
  1. Upgraded to Lucene 2.4.0 (yonik)

Modified: lucene/solr/trunk/src/java/org/apache/solr/handler/admin/LukeRequestHandler.java
URL: http://svn.apache.org/viewvc/lucene/solr/trunk/src/java/org/apache/solr/handler/admin/LukeRequestHandler.java?rev=763032&r1=763031&r2=763032&view=diff
==============================================================================
--- lucene/solr/trunk/src/java/org/apache/solr/handler/admin/LukeRequestHandler.java (original)
+++ lucene/solr/trunk/src/java/org/apache/solr/handler/admin/LukeRequestHandler.java Tue Apr  7 23:31:12 2009
@@ -506,7 +506,7 @@
 
   ///////////////////////////////////////////////////////////////////////////////////////
   
-  private static class TermHistogram 
+  static class TermHistogram 
   {
     int maxBucket = -1;
     public Map<Integer,Integer> hist = new HashMap<Integer, Integer>();
@@ -514,8 +514,7 @@
     private static final double LOG2 = Math.log( 2 );
     public static int getPowerOfTwoBucket( int num )
     {
-      int exp = (int)Math.ceil( (Math.log( num ) / LOG2 ) );
-      return (int) Math.pow( 2, exp );
+      return Math.max(1, Integer.highestOneBit(num-1) << 1);
     }
     
     public void add( int df )

Added: lucene/solr/trunk/src/test/org/apache/solr/handler/admin/LukeRequestHandlerTest.java
URL: http://svn.apache.org/viewvc/lucene/solr/trunk/src/test/org/apache/solr/handler/admin/LukeRequestHandlerTest.java?rev=763032&view=auto
==============================================================================
--- lucene/solr/trunk/src/test/org/apache/solr/handler/admin/LukeRequestHandlerTest.java (added)
+++ lucene/solr/trunk/src/test/org/apache/solr/handler/admin/LukeRequestHandlerTest.java Tue Apr  7 23:31:12 2009
@@ -0,0 +1,52 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.solr.handler.admin;
+
+import junit.framework.TestCase;
+
+import org.apache.solr.common.util.SimpleOrderedMap;
+
+/**
+ * :TODO: currently only tests some of the utilities in the LukeRequestHandler
+ */
+public class LukeRequestHandlerTest extends TestCase {
+  
+  /** tests some simple edge cases */
+  public void testHistogramPowerOfTwoBucket() {
+    assertHistoBucket(1,  1);
+    assertHistoBucket(2,  2);
+    assertHistoBucket(4,  3);
+    assertHistoBucket(4,  4);
+    assertHistoBucket(8,  5);
+    assertHistoBucket(8,  6);
+    assertHistoBucket(8,  7);
+    assertHistoBucket(8,  8);
+    assertHistoBucket(16, 9);
+
+    final int MAX_VALID = ((Integer.MAX_VALUE/2)+1)/2;
+    
+    assertHistoBucket(MAX_VALID,   MAX_VALID-1 );
+    assertHistoBucket(MAX_VALID,   MAX_VALID   );
+    assertHistoBucket(MAX_VALID*2, MAX_VALID+1 );
+    
+  }
+  private void assertHistoBucket(int expected, int in) {
+    assertEquals("histobucket: " + in, expected,
+                 LukeRequestHandler.TermHistogram.getPowerOfTwoBucket( in ));
+  }
+}

Propchange: lucene/solr/trunk/src/test/org/apache/solr/handler/admin/LukeRequestHandlerTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: lucene/solr/trunk/src/test/org/apache/solr/handler/admin/LukeRequestHandlerTest.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL