mirror of https://github.com/apache/lucene.git
LUCENE-7269: also handle annoying schema ghost corner case where number of docs with points in a segment is 0
This commit is contained in:
parent
a492117576
commit
b0b8d5795e
|
@ -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
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in New Issue