Skip to content

armgit / solr

Public Imported from GitHub
0

Apache Solr open-source search software

LUCENE-7269: also handle annoying schema ghost corner case where number of docs with points in a segment is 0

Mike McCandlessb0b8d5795edb
diff --git a/lucene/core/src/java/org/apache/lucene/util/DocIdSetBuilder.java b/lucene/core/src/java/org/apache/lucene/util/DocIdSetBuilder.java
index a00fdca7e1d..0301ba8dbb0 100644
--- a/lucene/core/src/java/org/apache/lucene/util/DocIdSetBuilder.java
+++ b/lucene/core/src/java/org/apache/lucene/util/DocIdSetBuilder.java
@@ -101,13 +101,16 @@ public final class DocIdSetBuilder {
DocIdSetBuilder(int maxDoc, int docCount, long valueCount) {
this.maxDoc = maxDoc;
this.multivalued = docCount < 0 || docCount != valueCount;
- this.numValuesPerDoc = (docCount < 0 || valueCount < 0)
- // assume one value per doc, this means the cost will be overestimated
- // if the docs are actually multi-valued
- ? 1
- // otherwise compute from index stats
- : (double) valueCount / docCount;
- assert numValuesPerDoc >= 1;
+ if (docCount <= 0 || valueCount < 0) {
+ // assume one value per doc, this means the cost will be overestimated
+ // if the docs are actually multi-valued
+ this.numValuesPerDoc = 1;
+ } else {
+ // otherwise compute from index stats
+ this.numValuesPerDoc = (double) valueCount / docCount;
+ }
+
+ assert numValuesPerDoc >= 1: "valueCount=" + valueCount + " docCount=" + docCount;
// For ridiculously small sets, we'll just use a sorted int[]
// maxDoc >>> 7 is a good value if you want to save memory, lower values
diff --git a/lucene/core/src/test/org/apache/lucene/util/TestDocIdSetBuilder.java b/lucene/core/src/test/org/apache/lucene/util/TestDocIdSetBuilder.java
index 5dd8eb30697..62e85fef088 100644
--- a/lucene/core/src/test/org/apache/lucene/util/TestDocIdSetBuilder.java
+++ b/lucene/core/src/test/org/apache/lucene/util/TestDocIdSetBuilder.java
@@ -161,6 +161,12 @@ public class TestDocIdSetBuilder extends LuceneTestCase {
assertEquals(new BitDocIdSet(expected), builder.build());
}
+ public void testEmptyPoints() throws IOException {
+ PointValues values = new DummyPointValues(0, 0);
+ DocIdSetBuilder builder = new DocIdSetBuilder(1, values, "foo");
+ assertEquals(1d, builder.numValuesPerDoc, 0d);
+ }
+
public void testLeverageStats() throws IOException {
// single-valued points
PointValues values = new DummyPointValues(42, 42);