Skip to content

Apache Lucene open-source search software

fix distributed facet counts when field may not exist in shard

Yonik Seeley160f664e5f0e
diff --git a/CHANGES.txt b/CHANGES.txt
index 452e9b3d136..cb14bdd3742 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -206,7 +206,7 @@ New Features
query faceting, highlighting, and debug information are supported
in distributed mode.
(Sharad Agarwal, Patrick O'Leary, Sabyasachi Dalal, Stu Hood,
- ryan, yonik)
+ Jayson Minard, ryan, yonik)
41. SOLR-356: Pluggable functions (value sources) that allow
registration of new functions via solrconfig.xml
diff --git a/src/java/org/apache/solr/handler/component/FacetComponent.java b/src/java/org/apache/solr/handler/component/FacetComponent.java
index bdcec74f34e..151d49fa775 100644
--- a/src/java/org/apache/solr/handler/component/FacetComponent.java
+++ b/src/java/org/apache/solr/handler/component/FacetComponent.java
@@ -233,7 +233,7 @@ public class FacetComponent extends SearchComponent
for (DistribFieldFacet dff : fi.topFacets.values()) {
ShardFacetCount[] counts = dff.getSorted();
int ntop = Math.min(counts.length, dff.offset + dff.limit);
- long smallestCount = counts[ntop-1].count;
+ long smallestCount = counts.length == 0 ? 0 : counts[ntop-1].count;
for (int i=0; i<counts.length; i++) {
ShardFacetCount sfc = counts[i];
diff --git a/src/test/org/apache/solr/TestDistributedSearch.java b/src/test/org/apache/solr/TestDistributedSearch.java
index d0f9ee158d8..6a67de267ad 100755
--- a/src/test/org/apache/solr/TestDistributedSearch.java
+++ b/src/test/org/apache/solr/TestDistributedSearch.java
@@ -477,6 +477,7 @@ public class TestDistributedSearch extends TestCase {
query("q","*:*", "rows",100, "facet","true", "facet.query","quick", "facet.query","all", "facet.query","*:*");
query("q","*:*", "rows",100, "facet","true", "facet.field",t1, "facet.offset",1);
query("q","*:*", "rows",100, "facet","true", "facet.field",t1,"facet.mincount",2);
+ query("q","*:*", "rows",100, "facet","true", "facet.field","missing_field_t","facet.mincount",2);
// index the same document to two servers and make sure things