Skip to content

Apache Lucene open-source search software

SOLR-6037: Fixed incorrect max/sum/stddev for Date fields in StatsComponent

Chris M. Hostetter6821905d244b
diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt
index 4d0fa23a713..2214a0de728 100644
--- a/solr/CHANGES.txt
+++ b/solr/CHANGES.txt
@@ -126,6 +126,9 @@ Bug Fixes
* SOLR-6030: Use System.nanoTime() instead of currentTimeInMills() in LRUCache.warm.
(Tomás Fernández Löbbe via shalin)
+* SOLR-6037: Fixed incorrect max/sum/stddev for Date fields in StatsComponent
+ (Brett Lucey, hossman)
+
Other Changes
---------------------
diff --git a/solr/core/src/java/org/apache/solr/handler/component/StatsValuesFactory.java b/solr/core/src/java/org/apache/solr/handler/component/StatsValuesFactory.java
index 591f23bb8d5..c18624d1fe5 100644
--- a/solr/core/src/java/org/apache/solr/handler/component/StatsValuesFactory.java
+++ b/solr/core/src/java/org/apache/solr/handler/component/StatsValuesFactory.java
@@ -390,7 +390,7 @@ class EnumStatsValues extends AbstractStatsValues<EnumFieldValue> {
*/
class DateStatsValues extends AbstractStatsValues<Date> {
- private long sum = -1;
+ private long sum = 0;
double sumOfSquares = 0;
public DateStatsValues(SchemaField sf, boolean calcDistinct) {
@@ -433,10 +433,10 @@ class DateStatsValues extends AbstractStatsValues<Date> {
*/
@Override
protected void updateMinMax(Date min, Date max) {
- if(this.min==null || this.min.after(min)) {
+ if(null != min && (this.min==null || this.min.after(min))) {
this.min = min;
}
- if(this.max==null || this.max.before(min)) {
+ if(null != max && (this.max==null || this.max.before(max))) {
this.max = max;
}
}
diff --git a/solr/core/src/test/org/apache/solr/TestDistributedSearch.java b/solr/core/src/test/org/apache/solr/TestDistributedSearch.java
index d268c13afda..6c06ec2e18c 100644
--- a/solr/core/src/test/org/apache/solr/TestDistributedSearch.java
+++ b/solr/core/src/test/org/apache/solr/TestDistributedSearch.java
@@ -264,7 +264,17 @@ public class TestDistributedSearch extends BaseDistributedSearchTestCase {
// test field that is valid in schema and missing in some shards
query("q","*:*", "rows",100, "facet","true", "facet.field",oddField, "facet.mincount",2);
+ query("q","*:*", "sort",i1+" desc", "stats", "true", "stats.field", "stats_dt");
query("q","*:*", "sort",i1+" desc", "stats", "true", "stats.field", i1);
+ query("q","*:*", "sort",i1+" desc", "stats", "true", "stats.field", tdate_a);
+ query("q","*:*", "sort",i1+" desc", "stats", "true", "stats.field", tdate_b);
+
+ handle.put("stats_fields", UNORDERED);
+ query("q","*:*", "sort",i1+" desc", "stats", "true",
+ "stats.field", "stats_dt",
+ "stats.field", i1,
+ "stats.field", tdate_a,
+ "stats.field", tdate_b);
/*** TODO: the failure may come back in "exception"
try {
@@ -417,7 +427,12 @@ public class TestDistributedSearch extends BaseDistributedSearchTestCase {
del("*:*"); // delete all docs and test stats request
commit();
try {
- query("q", "*:*", "stats", "true", "stats.field", "stats_dt", "stats.calcdistinct", "true");
+ query("q", "*:*", "stats", "true",
+ "stats.field", "stats_dt",
+ "stats.field", i1,
+ "stats.field", tdate_a,
+ "stats.field", tdate_b,
+ "stats.calcdistinct", "true");
} catch (Exception e) {
log.error("Exception on distrib stats request on empty index", e);
fail("NullPointerException with stats request on empty index");