lucene-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From er...@apache.org
Subject svn commit: r1293272 - in /lucene/dev/branches/branch_3x/solr/core/src: java/org/apache/solr/handler/component/StatsValuesFactory.java test/org/apache/solr/handler/component/StatsComponentTest.java
Date Fri, 24 Feb 2012 14:39:25 GMT
Author: erick
Date: Fri Feb 24 14:39:24 2012
New Revision: 1293272

URL: http://svn.apache.org/viewvc?rev=1293272&view=rev
Log:
Fix for Solr-3160, Thanks Luca Cavanna!

Modified:
    lucene/dev/branches/branch_3x/solr/core/src/java/org/apache/solr/handler/component/StatsValuesFactory.java
    lucene/dev/branches/branch_3x/solr/core/src/test/org/apache/solr/handler/component/StatsComponentTest.java

Modified: lucene/dev/branches/branch_3x/solr/core/src/java/org/apache/solr/handler/component/StatsValuesFactory.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_3x/solr/core/src/java/org/apache/solr/handler/component/StatsValuesFactory.java?rev=1293272&r1=1293271&r2=1293272&view=diff
==============================================================================
--- lucene/dev/branches/branch_3x/solr/core/src/java/org/apache/solr/handler/component/StatsValuesFactory.java
(original)
+++ lucene/dev/branches/branch_3x/solr/core/src/java/org/apache/solr/handler/component/StatsValuesFactory.java
Fri Feb 24 14:39:24 2012
@@ -17,16 +17,16 @@
 
 package org.apache.solr.handler.component;
 
-import java.text.ParseException;
-import java.util.Date;
-import java.util.Map;
-import java.util.HashMap;
-
 import org.apache.solr.common.SolrException;
 import org.apache.solr.common.util.NamedList;
 import org.apache.solr.common.util.SimpleOrderedMap;
 import org.apache.solr.schema.*;
 
+import java.text.ParseException;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.Map;
+
 /**
  * Factory class for creating instance of {@link org.apache.solr.handler.component.StatsValues}
  */
@@ -64,7 +64,7 @@ public class StatsValuesFactory {
 /**
  * Abstract implementation of {@link org.apache.solr.handler.component.StatsValues} that
provides the default behavior
  * for most StatsValues implementations.
- *
+ * <p/>
  * There are very few requirements placed on what statistics concrete implementations should
collect, with the only required
  * statistics being the minimum and maximum values.
  */
@@ -171,7 +171,7 @@ abstract class AbstractStatsValues<T> im
     res.add("missing", missing);
     addTypeSpecificStats(res);
 
-     // add the facet stats
+    // add the facet stats
     NamedList<NamedList<?>> nl = new SimpleOrderedMap<NamedList<?>>();
     for (Map.Entry<String, Map<String, StatsValues>> entry : facets.entrySet())
{
       NamedList<NamedList<?>> nl2 = new SimpleOrderedMap<NamedList<?>>();
@@ -230,7 +230,7 @@ abstract class AbstractStatsValues<T> im
   protected abstract void addTypeSpecificStats(NamedList<Object> res);
 }
 
- /**
+/**
  * Implementation of StatsValues that supports Double values
  */
 class NumericStatsValues extends AbstractStatsValues<Number> {
@@ -248,8 +248,8 @@ class NumericStatsValues extends Abstrac
    * {@inheritDoc}
    */
   public void updateTypeSpecificStats(NamedList stv) {
-    sum += ((Number)stv.get("sum")).doubleValue();
-    sumOfSquares += ((Number)stv.get("sumOfSquares")).doubleValue();
+    sum += ((Number) stv.get("sum")).doubleValue();
+    sumOfSquares += ((Number) stv.get("sumOfSquares")).doubleValue();
   }
 
   /**
@@ -270,7 +270,7 @@ class NumericStatsValues extends Abstrac
     sum += value * count;
   }
 
-   /**
+  /**
    * {@inheritDoc}
    */
   protected void updateMinMax(Number min, Number max) {
@@ -347,14 +347,14 @@ class DateStatsValues extends AbstractSt
     sum += value.getTime() * count;
   }
 
-   /**
+  /**
    * {@inheritDoc}
    */
   protected void updateMinMax(Date min, Date max) {
-    if(this.min==null || this.min.after(min)) {
+    if (this.min == null || this.min.after(min)) {
       this.min = min;
     }
-    if(this.max==null || this.max.before(min)) {
+    if (this.max == null || this.max.before(min)) {
       this.max = max;
     }
   }
@@ -381,7 +381,9 @@ class DateStatsValues extends AbstractSt
    */
   protected void addTypeSpecificStats(NamedList<Object> res) {
     res.add("sum", new Date(sum));
-    res.add("mean", new Date(sum / count));
+    if (count > 0) {
+      res.add("mean", new Date(sum / count));
+    }
   }
 }
 
@@ -415,7 +417,7 @@ class StringStatsValues extends Abstract
     // No type specific stats
   }
 
-   /**
+  /**
    * {@inheritDoc}
    */
   protected void updateMinMax(String min, String max) {

Modified: lucene/dev/branches/branch_3x/solr/core/src/test/org/apache/solr/handler/component/StatsComponentTest.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_3x/solr/core/src/test/org/apache/solr/handler/component/StatsComponentTest.java?rev=1293272&r1=1293271&r2=1293272&view=diff
==============================================================================
--- lucene/dev/branches/branch_3x/solr/core/src/test/org/apache/solr/handler/component/StatsComponentTest.java
(original)
+++ lucene/dev/branches/branch_3x/solr/core/src/test/org/apache/solr/handler/component/StatsComponentTest.java
Fri Feb 24 14:39:24 2012
@@ -16,14 +16,6 @@ package org.apache.solr.handler.componen
  * limitations under the License.
  */
 
-import java.util.Date;
-import java.util.Locale;
-import java.util.Map;
-import java.util.HashMap;
-import java.util.TimeZone;
-import java.text.DateFormat;
-import java.text.SimpleDateFormat;
-
 import org.apache.solr.common.params.CommonParams;
 import org.apache.solr.common.params.MapSolrParams;
 import org.apache.solr.common.params.StatsParams;
@@ -32,6 +24,10 @@ import org.apache.solr.request.LocalSolr
 import org.apache.solr.request.SolrQueryRequest;
 import org.apache.solr.util.AbstractSolrTestCase;
 
+import java.text.DateFormat;
+import java.text.SimpleDateFormat;
+import java.util.*;
+
 
 /**
  * Statistics Component Test
@@ -55,9 +51,9 @@ public class StatsComponentTest extends 
   }
 
   public void testStats() throws Exception {
-    for (String f : new String[] {
-            "stats_i","stats_l","stats_f","stats_d",
-            "stats_ti","stats_tl","stats_tf","stats_td"
+    for (String f : new String[]{
+        "stats_i", "stats_l", "stats_f", "stats_d",
+        "stats_ti", "stats_tl", "stats_tf", "stats_td"
     }) {
       doTestFieldStatisticsResult(f);
       doTestFieldStatisticsMissingResult(f);
@@ -65,13 +61,13 @@ public class StatsComponentTest extends 
       doTestFacetStatisticsMissingResult(f);
     }
 
-    for (String f : new String[] {"stats_ii", // plain int
-            "stats_is",    // sortable int
-            "stats_tis","stats_tfs","stats_tls","stats_tds"  // trie fields
-                                  }) {
+    for (String f : new String[]{"stats_ii", // plain int
+        "stats_is",    // sortable int
+        "stats_tis", "stats_tfs", "stats_tls", "stats_tds"  // trie fields
+    }) {
       doTestMVFieldStatisticsResult(f);
     }
-    
+
   }
 
   public void doTestFieldStatisticsResult(String f) throws Exception {
@@ -81,16 +77,16 @@ public class StatsComponentTest extends 
     assertU(adoc("id", "4", f, "-40"));
     assertU(commit());
 
-    assertQ("test statistics values", req("q","*:*", "stats","true", "stats.field",f)
-            , "//double[@name='min'][.='-40.0']"
-            , "//double[@name='max'][.='-10.0']"
-            , "//double[@name='sum'][.='-100.0']"
-            , "//long[@name='count'][.='4']"
-            , "//long[@name='missing'][.='0']"
-            , "//double[@name='sumOfSquares'][.='3000.0']"
-            , "//double[@name='mean'][.='-25.0']"
-            , "//double[@name='stddev'][.='12.909944487358056']"
-    );    
+    assertQ("test statistics values", req("q", "*:*", "stats", "true", "stats.field", f)
+        , "//double[@name='min'][.='-40.0']"
+        , "//double[@name='max'][.='-10.0']"
+        , "//double[@name='sum'][.='-100.0']"
+        , "//long[@name='count'][.='4']"
+        , "//long[@name='missing'][.='0']"
+        , "//double[@name='sumOfSquares'][.='3000.0']"
+        , "//double[@name='mean'][.='-25.0']"
+        , "//double[@name='stddev'][.='12.909944487358056']"
+    );
   }
 
 
@@ -102,48 +98,48 @@ public class StatsComponentTest extends 
     assertU(adoc("id", "5", "active_s", "false"));
     assertU(commit());
 
-    assertQ("test statistics values", req("q","*:*", "stats","true", "stats.field",f)
-            , "//double[@name='min'][.='-100.0']"
-            , "//double[@name='max'][.='200.0']"
-            , "//double[@name='sum'][.='9.0']"
-            , "//long[@name='count'][.='8']"
-            , "//long[@name='missing'][.='1']"
-            , "//double[@name='sumOfSquares'][.='53101.0']"
-            , "//double[@name='mean'][.='1.125']"
-            , "//double[@name='stddev'][.='87.08852228787508']"
+    assertQ("test statistics values", req("q", "*:*", "stats", "true", "stats.field", f)
+        , "//double[@name='min'][.='-100.0']"
+        , "//double[@name='max'][.='200.0']"
+        , "//double[@name='sum'][.='9.0']"
+        , "//long[@name='count'][.='8']"
+        , "//long[@name='missing'][.='1']"
+        , "//double[@name='sumOfSquares'][.='53101.0']"
+        , "//double[@name='mean'][.='1.125']"
+        , "//double[@name='stddev'][.='87.08852228787508']"
     );
 
-    assertQ("test statistics values", req("q","*:*", "stats","true", "stats.field",f, "stats.facet","active_s")
-            , "//double[@name='min'][.='-100.0']"
-            , "//double[@name='max'][.='200.0']"
-            , "//double[@name='sum'][.='9.0']"
-            , "//long[@name='count'][.='8']"
-            , "//long[@name='missing'][.='1']"
-            , "//double[@name='sumOfSquares'][.='53101.0']"
-            , "//double[@name='mean'][.='1.125']"
-            , "//double[@name='stddev'][.='87.08852228787508']"
+    assertQ("test statistics values", req("q", "*:*", "stats", "true", "stats.field", f,
"stats.facet", "active_s")
+        , "//double[@name='min'][.='-100.0']"
+        , "//double[@name='max'][.='200.0']"
+        , "//double[@name='sum'][.='9.0']"
+        , "//long[@name='count'][.='8']"
+        , "//long[@name='missing'][.='1']"
+        , "//double[@name='sumOfSquares'][.='53101.0']"
+        , "//double[@name='mean'][.='1.125']"
+        , "//double[@name='stddev'][.='87.08852228787508']"
     );
 
-    assertQ("test value for active_s=true", req("q","*:*", "stats","true", "stats.field",f,
"stats.facet","active_s")
-            , "//lst[@name='true']/double[@name='min'][.='-100.0']"
-            , "//lst[@name='true']/double[@name='max'][.='200.0']"
-            , "//lst[@name='true']/double[@name='sum'][.='70.0']"
-            , "//lst[@name='true']/long[@name='count'][.='4']"
-            , "//lst[@name='true']/long[@name='missing'][.='0']"
-            , "//lst[@name='true']/double[@name='sumOfSquares'][.='50500.0']"
-            , "//lst[@name='true']/double[@name='mean'][.='17.5']"
-            , "//lst[@name='true']/double[@name='stddev'][.='128.16005617976296']"
+    assertQ("test value for active_s=true", req("q", "*:*", "stats", "true", "stats.field",
f, "stats.facet", "active_s")
+        , "//lst[@name='true']/double[@name='min'][.='-100.0']"
+        , "//lst[@name='true']/double[@name='max'][.='200.0']"
+        , "//lst[@name='true']/double[@name='sum'][.='70.0']"
+        , "//lst[@name='true']/long[@name='count'][.='4']"
+        , "//lst[@name='true']/long[@name='missing'][.='0']"
+        , "//lst[@name='true']/double[@name='sumOfSquares'][.='50500.0']"
+        , "//lst[@name='true']/double[@name='mean'][.='17.5']"
+        , "//lst[@name='true']/double[@name='stddev'][.='128.16005617976296']"
     );
 
-    assertQ("test value for active_s=false", req("q","*:*", "stats","true", "stats.field",f,
"stats.facet","active_s", "indent","true")
-            , "//lst[@name='false']/double[@name='min'][.='-40.0']"
-            , "//lst[@name='false']/double[@name='max'][.='10.0']"
-            , "//lst[@name='false']/double[@name='sum'][.='-61.0']"
-            , "//lst[@name='false']/long[@name='count'][.='4']"
-            , "//lst[@name='false']/long[@name='missing'][.='1']"
-            , "//lst[@name='false']/double[@name='sumOfSquares'][.='2601.0']"
-            , "//lst[@name='false']/double[@name='mean'][.='-15.25']"
-            , "//lst[@name='false']/double[@name='stddev'][.='23.59908190304586']"
+    assertQ("test value for active_s=false", req("q", "*:*", "stats", "true", "stats.field",
f, "stats.facet", "active_s", "indent", "true")
+        , "//lst[@name='false']/double[@name='min'][.='-40.0']"
+        , "//lst[@name='false']/double[@name='max'][.='10.0']"
+        , "//lst[@name='false']/double[@name='sum'][.='-61.0']"
+        , "//lst[@name='false']/long[@name='count'][.='4']"
+        , "//lst[@name='false']/long[@name='missing'][.='1']"
+        , "//lst[@name='false']/double[@name='sumOfSquares'][.='2601.0']"
+        , "//lst[@name='false']/double[@name='mean'][.='-15.25']"
+        , "//lst[@name='false']/double[@name='stddev'][.='23.59908190304586']"
     );
 
 
@@ -166,10 +162,10 @@ public class StatsComponentTest extends 
     SolrQueryRequest req = new LocalSolrQueryRequest(core, new MapSolrParams(args));
 
     assertQ("test string statistics values", req,
-            "//str[@name='min'][.='string1']",
-            "//str[@name='max'][.='string3']",
-            "//long[@name='count'][.='3']",
-            "//long[@name='missing'][.='1']");
+        "//str[@name='min'][.='string1']",
+        "//str[@name='max'][.='string3']",
+        "//long[@name='count'][.='3']",
+        "//long[@name='missing'][.='1']");
   }
 
   public void testFieldStatisticsResultsDateField() throws Exception {
@@ -194,16 +190,15 @@ public class StatsComponentTest extends 
     SolrQueryRequest req = new LocalSolrQueryRequest(core, new MapSolrParams(args));
 
     assertQ("test date statistics values", req,
-            "//long[@name='count'][.='2']",
-            "//long[@name='missing'][.='1']",
-            "//date[@name='min'][.='1970-01-02T10:17:36Z']",
-            "//date[@name='max'][.='1970-01-12T10:20:54Z']",
-            "//date[@name='sum'][.='1970-01-13T20:38:30Z']",
-            "//date[@name='mean'][.='1970-01-07T10:19:15Z']");
+        "//long[@name='count'][.='2']",
+        "//long[@name='missing'][.='1']",
+        "//date[@name='min'][.='1970-01-02T10:17:36Z']",
+        "//date[@name='max'][.='1970-01-12T10:20:54Z']",
+        "//date[@name='sum'][.='1970-01-13T20:38:30Z']",
+        "//date[@name='mean'][.='1970-01-07T10:19:15Z']");
   }
 
 
-
   public void doTestFieldStatisticsMissingResult(String f) throws Exception {
     assertU(adoc("id", "1", f, "-10"));
     assertU(adoc("id", "2", f, "-20"));
@@ -211,15 +206,15 @@ public class StatsComponentTest extends 
     assertU(adoc("id", "4", f, "-40"));
     assertU(commit());
 
-    assertQ("test statistics values", req("q","*:*", "stats","true", "stats.field",f)
-            , "//double[@name='min'][.='-40.0']"
-            , "//double[@name='max'][.='-10.0']"
-            , "//double[@name='sum'][.='-70.0']"
-            , "//long[@name='count'][.='3']"
-            , "//long[@name='missing'][.='1']"
-            , "//double[@name='sumOfSquares'][.='2100.0']"
-            , "//double[@name='mean'][.='-23.333333333333332']"
-            , "//double[@name='stddev'][.='15.275252316519467']"
+    assertQ("test statistics values", req("q", "*:*", "stats", "true", "stats.field", f)
+        , "//double[@name='min'][.='-40.0']"
+        , "//double[@name='max'][.='-10.0']"
+        , "//double[@name='sum'][.='-70.0']"
+        , "//long[@name='count'][.='3']"
+        , "//long[@name='missing'][.='1']"
+        , "//double[@name='sumOfSquares'][.='2100.0']"
+        , "//double[@name='mean'][.='-23.333333333333332']"
+        , "//double[@name='stddev'][.='15.275252316519467']"
     );
   }
 
@@ -230,56 +225,114 @@ public class StatsComponentTest extends 
     assertU(adoc("id", "4", f, "40", "active_s", "false"));
     assertU(commit());
 
-    assertQ("test value for active_s=true", req("q","*:*", "stats","true", "stats.field",f,
"stats.facet","active_s","indent","true")
-            , "//lst[@name='true']/double[@name='min'][.='10.0']"
-            , "//lst[@name='true']/double[@name='max'][.='20.0']"
-            , "//lst[@name='true']/double[@name='sum'][.='30.0']"
-            , "//lst[@name='true']/long[@name='count'][.='2']"
-            , "//lst[@name='true']/long[@name='missing'][.='0']"
-            , "//lst[@name='true']/double[@name='sumOfSquares'][.='500.0']"
-            , "//lst[@name='true']/double[@name='mean'][.='15.0']"
-            , "//lst[@name='true']/double[@name='stddev'][.='7.0710678118654755']"
+    assertQ("test value for active_s=true", req("q", "*:*", "stats", "true", "stats.field",
f, "stats.facet", "active_s", "indent", "true")
+        , "//lst[@name='true']/double[@name='min'][.='10.0']"
+        , "//lst[@name='true']/double[@name='max'][.='20.0']"
+        , "//lst[@name='true']/double[@name='sum'][.='30.0']"
+        , "//lst[@name='true']/long[@name='count'][.='2']"
+        , "//lst[@name='true']/long[@name='missing'][.='0']"
+        , "//lst[@name='true']/double[@name='sumOfSquares'][.='500.0']"
+        , "//lst[@name='true']/double[@name='mean'][.='15.0']"
+        , "//lst[@name='true']/double[@name='stddev'][.='7.0710678118654755']"
     );
 
-    assertQ("test value for active_s=false", req("q","*:*", "stats","true", "stats.field",f,
"stats.facet","active_s")
-            , "//lst[@name='false']/double[@name='min'][.='30.0']"
-            , "//lst[@name='false']/double[@name='max'][.='40.0']"
-            , "//lst[@name='false']/double[@name='sum'][.='70.0']"
-            , "//lst[@name='false']/long[@name='count'][.='2']"
-            , "//lst[@name='false']/long[@name='missing'][.='0']"
-            , "//lst[@name='false']/double[@name='sumOfSquares'][.='2500.0']"
-            , "//lst[@name='false']/double[@name='mean'][.='35.0']"
-            , "//lst[@name='false']/double[@name='stddev'][.='7.0710678118654755']"
+    assertQ("test value for active_s=false", req("q", "*:*", "stats", "true", "stats.field",
f, "stats.facet", "active_s")
+        , "//lst[@name='false']/double[@name='min'][.='30.0']"
+        , "//lst[@name='false']/double[@name='max'][.='40.0']"
+        , "//lst[@name='false']/double[@name='sum'][.='70.0']"
+        , "//lst[@name='false']/long[@name='count'][.='2']"
+        , "//lst[@name='false']/long[@name='missing'][.='0']"
+        , "//lst[@name='false']/double[@name='sumOfSquares'][.='2500.0']"
+        , "//lst[@name='false']/double[@name='mean'][.='35.0']"
+        , "//lst[@name='false']/double[@name='stddev'][.='7.0710678118654755']"
     );
   }
-  
+
   public void doTestFacetStatisticsMissingResult(String f) throws Exception {
-	    assertU(adoc("id", "1", f, "10", "active_s", "true"));
-	    assertU(adoc("id", "2", f, "20", "active_s", "true"));
-	    assertU(adoc("id", "3", "active_s", "false"));
-	    assertU(adoc("id", "4", f, "40", "active_s", "false"));
-	    assertU(commit());
-
-	    assertQ("test value for active_s=true", req("q","*:*", "stats","true", "stats.field",f,
"stats.facet","active_s")
-	            , "//lst[@name='true']/double[@name='min'][.='10.0']"
-	            , "//lst[@name='true']/double[@name='max'][.='20.0']"
-	            , "//lst[@name='true']/double[@name='sum'][.='30.0']"
-	            , "//lst[@name='true']/long[@name='count'][.='2']"
-	            , "//lst[@name='true']/long[@name='missing'][.='0']"
-	            , "//lst[@name='true']/double[@name='sumOfSquares'][.='500.0']"
-	            , "//lst[@name='true']/double[@name='mean'][.='15.0']"
-	            , "//lst[@name='true']/double[@name='stddev'][.='7.0710678118654755']"
-	    );
-
-	    assertQ("test value for active_s=false", req("q","*:*", "stats","true", "stats.field",f,
"stats.facet","active_s")
-	            , "//lst[@name='false']/double[@name='min'][.='40.0']"
-	            , "//lst[@name='false']/double[@name='max'][.='40.0']"
-	            , "//lst[@name='false']/double[@name='sum'][.='40.0']"
-	            , "//lst[@name='false']/long[@name='count'][.='1']"
-	            , "//lst[@name='false']/long[@name='missing'][.='1']"
-	            , "//lst[@name='false']/double[@name='sumOfSquares'][.='1600.0']"
-	            , "//lst[@name='false']/double[@name='mean'][.='40.0']"
-	            , "//lst[@name='false']/double[@name='stddev'][.='0.0']"
-	    );
-	  }
+    assertU(adoc("id", "1", f, "10", "active_s", "true"));
+    assertU(adoc("id", "2", f, "20", "active_s", "true"));
+    assertU(adoc("id", "3", "active_s", "false"));
+    assertU(adoc("id", "4", f, "40", "active_s", "false"));
+    assertU(commit());
+
+    assertQ("test value for active_s=true", req("q", "*:*", "stats", "true", "stats.field",
f, "stats.facet", "active_s")
+        , "//lst[@name='true']/double[@name='min'][.='10.0']"
+        , "//lst[@name='true']/double[@name='max'][.='20.0']"
+        , "//lst[@name='true']/double[@name='sum'][.='30.0']"
+        , "//lst[@name='true']/long[@name='count'][.='2']"
+        , "//lst[@name='true']/long[@name='missing'][.='0']"
+        , "//lst[@name='true']/double[@name='sumOfSquares'][.='500.0']"
+        , "//lst[@name='true']/double[@name='mean'][.='15.0']"
+        , "//lst[@name='true']/double[@name='stddev'][.='7.0710678118654755']"
+    );
+
+    assertQ("test value for active_s=false", req("q", "*:*", "stats", "true", "stats.field",
f, "stats.facet", "active_s")
+        , "//lst[@name='false']/double[@name='min'][.='40.0']"
+        , "//lst[@name='false']/double[@name='max'][.='40.0']"
+        , "//lst[@name='false']/double[@name='sum'][.='40.0']"
+        , "//lst[@name='false']/long[@name='count'][.='1']"
+        , "//lst[@name='false']/long[@name='missing'][.='1']"
+        , "//lst[@name='false']/double[@name='sumOfSquares'][.='1600.0']"
+        , "//lst[@name='false']/double[@name='mean'][.='40.0']"
+        , "//lst[@name='false']/double[@name='stddev'][.='0.0']"
+    );
+  }
+
+  public void testFieldStatisticsResultsNumericFieldAlwaysMissing() throws Exception {
+    SolrCore core = h.getCore();
+    assertU(adoc("id", "1"));
+    assertU(adoc("id", "2"));
+    assertU(adoc("id", "3"));
+    assertU(adoc("id", "4"));
+    assertU(commit());
+
+    Map<String, String> args = new HashMap<String, String>();
+    args.put(CommonParams.Q, "*:*");
+    args.put(StatsParams.STATS, "true");
+    args.put(StatsParams.STATS_FIELD, "active_i");
+    args.put("indent", "true");
+    SolrQueryRequest req = new LocalSolrQueryRequest(core, new MapSolrParams(args));
+
+    assertQ("test string statistics values", req,
+        "//null[@name='active_i'][.='']");
+  }
+
+  public void testFieldStatisticsResultsStringFieldAlwaysMissing() throws Exception {
+    SolrCore core = h.getCore();
+    assertU(adoc("id", "1"));
+    assertU(adoc("id", "2"));
+    assertU(adoc("id", "3"));
+    assertU(adoc("id", "4"));
+    assertU(commit());
+
+    Map<String, String> args = new HashMap<String, String>();
+    args.put(CommonParams.Q, "*:*");
+    args.put(StatsParams.STATS, "true");
+    args.put(StatsParams.STATS_FIELD, "active_s");
+    args.put("indent", "true");
+    SolrQueryRequest req = new LocalSolrQueryRequest(core, new MapSolrParams(args));
+
+    assertQ("test string statistics values", req,
+        "//null[@name='active_s'][.='']");
+  }
+
+  //SOLR-3160
+  public void testFieldStatisticsResultsDateFieldAlwaysMissing() throws Exception {
+    SolrCore core = h.getCore();
+
+    assertU(adoc("id", "1"));
+    assertU(adoc("id", "2"));
+    assertU(adoc("id", "3"));
+    assertU(commit());
+
+    Map<String, String> args = new HashMap<String, String>();
+    args.put(CommonParams.Q, "*:*");
+    args.put(StatsParams.STATS, "true");
+    args.put(StatsParams.STATS_FIELD, "active_dt");
+    args.put("indent", "true");
+    SolrQueryRequest req = new LocalSolrQueryRequest(core, new MapSolrParams(args));
+
+    assertQ("test string statistics values", req,
+        "//null[@name='active_dt'][.='']");
+  }
 }



Mime
View raw message