You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by jp...@apache.org on 2021/12/02 15:34:02 UTC
[lucene] branch branch_9x updated (1b04807 -> cbd306f)
This is an automated email from the ASF dual-hosted git repository.
jpountz pushed a change to branch branch_9x
in repository https://gitbox.apache.org/repos/asf/lucene.git.
from 1b04807 Make EndiannessReverser(Data|Index)Input always reverse byte order. (#502)
new dd14424 LUCENE-10233: Store docIds as bitset to speed up addAll (#438)
new cbd306f LUCENE-10278: don't write zero-sized array in this test (#501)
The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
Summary of changes:
lucene/CHANGES.txt | 3 +
.../lucene/document/LatLonPointDistanceQuery.java | 5 ++
.../apache/lucene/document/RangeFieldQuery.java | 5 ++
.../org/apache/lucene/document/SpatialQuery.java | 5 ++
.../lucene/document/XYPointInGeometryQuery.java | 5 ++
.../java/org/apache/lucene/index/PointValues.java | 11 +++
.../org/apache/lucene/search/PointInSetQuery.java | 10 +++
.../org/apache/lucene/search/PointRangeQuery.java | 5 ++
...SetIterator.java => DocBaseBitSetIterator.java} | 69 ++++++++----------
.../org/apache/lucene/util/DocIdSetBuilder.java | 12 ++++
.../java/org/apache/lucene/util/FixedBitSet.java | 19 +++--
.../org/apache/lucene/util/bkd/DocIdsWriter.java | 84 +++++++++++++++++++++-
.../apache/lucene/util/bkd/TestDocIdsWriter.java | 22 +++++-
.../lucene/sandbox/search/MultiRangeQuery.java | 5 ++
.../spatial3d/PointInShapeIntersectVisitor.java | 7 ++
15 files changed, 220 insertions(+), 47 deletions(-)
copy lucene/core/src/java/org/apache/lucene/util/{BitSetIterator.java => DocBaseBitSetIterator.java} (52%)
[lucene] 01/02: LUCENE-10233: Store docIds as bitset to speed up addAll (#438)
Posted by jp...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
jpountz pushed a commit to branch branch_9x
in repository https://gitbox.apache.org/repos/asf/lucene.git
commit dd144248178538bf3eb1c021c1fca99ce87b342d
Author: gf2121 <52...@users.noreply.github.com>
AuthorDate: Wed Dec 1 22:31:05 2021 +0800
LUCENE-10233: Store docIds as bitset to speed up addAll (#438)
---
lucene/CHANGES.txt | 3 +
.../lucene/document/LatLonPointDistanceQuery.java | 5 ++
.../apache/lucene/document/RangeFieldQuery.java | 5 ++
.../org/apache/lucene/document/SpatialQuery.java | 5 ++
.../lucene/document/XYPointInGeometryQuery.java | 5 ++
.../java/org/apache/lucene/index/PointValues.java | 11 +++
.../org/apache/lucene/search/PointInSetQuery.java | 10 +++
.../org/apache/lucene/search/PointRangeQuery.java | 5 ++
.../apache/lucene/util/DocBaseBitSetIterator.java | 92 ++++++++++++++++++++++
.../org/apache/lucene/util/DocIdSetBuilder.java | 12 +++
.../java/org/apache/lucene/util/FixedBitSet.java | 19 +++--
.../org/apache/lucene/util/bkd/DocIdsWriter.java | 84 +++++++++++++++++++-
.../apache/lucene/util/bkd/TestDocIdsWriter.java | 18 +++++
.../lucene/sandbox/search/MultiRangeQuery.java | 5 ++
.../spatial3d/PointInShapeIntersectVisitor.java | 7 ++
15 files changed, 279 insertions(+), 7 deletions(-)
diff --git a/lucene/CHANGES.txt b/lucene/CHANGES.txt
index 65b5ec7..2dd659b 100644
--- a/lucene/CHANGES.txt
+++ b/lucene/CHANGES.txt
@@ -49,6 +49,9 @@ Improvements
Optimizations
---------------------
+* LUCENE-10233: Store BKD leaves' doc IDs as bitset in some cases (typically for low cardinality fields
+ or sorted indices) to speed up addAll. (Guo Feng, Adrien Grand)
+
* LUCENE-10225: Improve IntroSelector with 3-ways partitioning. (Bruno Roustant, Adrien Grand)
Bug Fixes
diff --git a/lucene/core/src/java/org/apache/lucene/document/LatLonPointDistanceQuery.java b/lucene/core/src/java/org/apache/lucene/document/LatLonPointDistanceQuery.java
index 06a2b9e..b1950e5 100644
--- a/lucene/core/src/java/org/apache/lucene/document/LatLonPointDistanceQuery.java
+++ b/lucene/core/src/java/org/apache/lucene/document/LatLonPointDistanceQuery.java
@@ -257,6 +257,11 @@ final class LatLonPointDistanceQuery extends Query {
}
@Override
+ public void visit(DocIdSetIterator iterator) throws IOException {
+ adder.add(iterator);
+ }
+
+ @Override
public void visit(int docID, byte[] packedValue) {
if (matches(packedValue)) {
visit(docID);
diff --git a/lucene/core/src/java/org/apache/lucene/document/RangeFieldQuery.java b/lucene/core/src/java/org/apache/lucene/document/RangeFieldQuery.java
index 0d0edbb..ab83969 100644
--- a/lucene/core/src/java/org/apache/lucene/document/RangeFieldQuery.java
+++ b/lucene/core/src/java/org/apache/lucene/document/RangeFieldQuery.java
@@ -467,6 +467,11 @@ public abstract class RangeFieldQuery extends Query {
}
@Override
+ public void visit(DocIdSetIterator iterator) throws IOException {
+ adder.add(iterator);
+ }
+
+ @Override
public void visit(int docID, byte[] leaf) throws IOException {
if (queryType.matches(ranges, leaf, numDims, bytesPerDim)) {
visit(docID);
diff --git a/lucene/core/src/java/org/apache/lucene/document/SpatialQuery.java b/lucene/core/src/java/org/apache/lucene/document/SpatialQuery.java
index 1d6f981..19a5d83 100644
--- a/lucene/core/src/java/org/apache/lucene/document/SpatialQuery.java
+++ b/lucene/core/src/java/org/apache/lucene/document/SpatialQuery.java
@@ -423,6 +423,11 @@ abstract class SpatialQuery extends Query {
}
@Override
+ public void visit(DocIdSetIterator iterator) throws IOException {
+ adder.add(iterator);
+ }
+
+ @Override
public void visit(int docID, byte[] t) {
if (leafPredicate.test(t)) {
visit(docID);
diff --git a/lucene/core/src/java/org/apache/lucene/document/XYPointInGeometryQuery.java b/lucene/core/src/java/org/apache/lucene/document/XYPointInGeometryQuery.java
index 3260845..1533463 100644
--- a/lucene/core/src/java/org/apache/lucene/document/XYPointInGeometryQuery.java
+++ b/lucene/core/src/java/org/apache/lucene/document/XYPointInGeometryQuery.java
@@ -86,6 +86,11 @@ final class XYPointInGeometryQuery extends Query {
}
@Override
+ public void visit(DocIdSetIterator iterator) throws IOException {
+ adder.add(iterator);
+ }
+
+ @Override
public void visit(int docID, byte[] packedValue) {
double x = XYEncodingUtils.decode(packedValue, 0);
double y = XYEncodingUtils.decode(packedValue, Integer.BYTES);
diff --git a/lucene/core/src/java/org/apache/lucene/index/PointValues.java b/lucene/core/src/java/org/apache/lucene/index/PointValues.java
index 4541645..64229d1 100644
--- a/lucene/core/src/java/org/apache/lucene/index/PointValues.java
+++ b/lucene/core/src/java/org/apache/lucene/index/PointValues.java
@@ -288,6 +288,17 @@ public abstract class PointValues {
void visit(int docID) throws IOException;
/**
+ * Similar to {@link IntersectVisitor#visit(int)}, but a bulk visit and implements may have
+ * their optimizations.
+ */
+ default void visit(DocIdSetIterator iterator) throws IOException {
+ int docID;
+ while ((docID = iterator.nextDoc()) != DocIdSetIterator.NO_MORE_DOCS) {
+ visit(docID);
+ }
+ }
+
+ /**
* Called for all documents in a leaf cell that crosses the query. The consumer should
* scrutinize the packedValue to decide whether to accept it. In the 1D case, values are visited
* in increasing order, and in the case of ties, in increasing docID order.
diff --git a/lucene/core/src/java/org/apache/lucene/search/PointInSetQuery.java b/lucene/core/src/java/org/apache/lucene/search/PointInSetQuery.java
index e85b7f1..a490727 100644
--- a/lucene/core/src/java/org/apache/lucene/search/PointInSetQuery.java
+++ b/lucene/core/src/java/org/apache/lucene/search/PointInSetQuery.java
@@ -238,6 +238,11 @@ public abstract class PointInSetQuery extends Query implements Accountable {
}
@Override
+ public void visit(DocIdSetIterator iterator) throws IOException {
+ adder.add(iterator);
+ }
+
+ @Override
public void visit(int docID, byte[] packedValue) {
if (matches(packedValue)) {
visit(docID);
@@ -337,6 +342,11 @@ public abstract class PointInSetQuery extends Query implements Accountable {
}
@Override
+ public void visit(DocIdSetIterator iterator) throws IOException {
+ adder.add(iterator);
+ }
+
+ @Override
public void visit(int docID, byte[] packedValue) {
assert packedValue.length == pointBytes.length;
if (Arrays.equals(packedValue, pointBytes)) {
diff --git a/lucene/core/src/java/org/apache/lucene/search/PointRangeQuery.java b/lucene/core/src/java/org/apache/lucene/search/PointRangeQuery.java
index 6e69c74..06b7836 100644
--- a/lucene/core/src/java/org/apache/lucene/search/PointRangeQuery.java
+++ b/lucene/core/src/java/org/apache/lucene/search/PointRangeQuery.java
@@ -179,6 +179,11 @@ public abstract class PointRangeQuery extends Query {
}
@Override
+ public void visit(DocIdSetIterator iterator) throws IOException {
+ adder.add(iterator);
+ }
+
+ @Override
public void visit(int docID, byte[] packedValue) {
if (matches(packedValue)) {
visit(docID);
diff --git a/lucene/core/src/java/org/apache/lucene/util/DocBaseBitSetIterator.java b/lucene/core/src/java/org/apache/lucene/util/DocBaseBitSetIterator.java
new file mode 100644
index 0000000..ba05f94
--- /dev/null
+++ b/lucene/core/src/java/org/apache/lucene/util/DocBaseBitSetIterator.java
@@ -0,0 +1,92 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.lucene.util;
+
+import org.apache.lucene.search.DocIdSetIterator;
+
+/**
+ * A {@link DocIdSetIterator} like {@link BitSetIterator} but has a doc base in onder to avoid
+ * storing previous 0s.
+ */
+public class DocBaseBitSetIterator extends DocIdSetIterator {
+
+ private final FixedBitSet bits;
+ private final int length;
+ private final long cost;
+ private final int docBase;
+ private int doc = -1;
+
+ public DocBaseBitSetIterator(FixedBitSet bits, long cost, int docBase) {
+ if (cost < 0) {
+ throw new IllegalArgumentException("cost must be >= 0, got " + cost);
+ }
+ if ((docBase & 63) != 0) {
+ throw new IllegalArgumentException("docBase need to be a multiple of 64");
+ }
+ this.bits = bits;
+ this.length = bits.length() + docBase;
+ this.cost = cost;
+ this.docBase = docBase;
+ }
+
+ /**
+ * Get the {@link FixedBitSet}. A docId will exist in this {@link DocIdSetIterator} if the bitset
+ * contains the (docId - {@link #getDocBase})
+ *
+ * @return the offset docId bitset
+ */
+ public FixedBitSet getBitSet() {
+ return bits;
+ }
+
+ @Override
+ public int docID() {
+ return doc;
+ }
+
+ /**
+ * Get the docBase. It is guaranteed that docBase is a multiple of 64.
+ *
+ * @return the docBase
+ */
+ public int getDocBase() {
+ return docBase;
+ }
+
+ @Override
+ public int nextDoc() {
+ return advance(doc + 1);
+ }
+
+ @Override
+ public int advance(int target) {
+ if (target >= length) {
+ return doc = NO_MORE_DOCS;
+ }
+ int next = bits.nextSetBit(Math.max(0, target - docBase));
+ if (next == NO_MORE_DOCS) {
+ return doc = NO_MORE_DOCS;
+ } else {
+ return doc = next + docBase;
+ }
+ }
+
+ @Override
+ public long cost() {
+ return cost;
+ }
+}
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 0abf92e..67b3dde 100644
--- a/lucene/core/src/java/org/apache/lucene/util/DocIdSetBuilder.java
+++ b/lucene/core/src/java/org/apache/lucene/util/DocIdSetBuilder.java
@@ -43,6 +43,13 @@ public final class DocIdSetBuilder {
*/
public abstract static class BulkAdder {
public abstract void add(int doc);
+
+ public void add(DocIdSetIterator iterator) throws IOException {
+ int docID;
+ while ((docID = iterator.nextDoc()) != DocIdSetIterator.NO_MORE_DOCS) {
+ add(docID);
+ }
+ }
}
private static class FixedBitSetAdder extends BulkAdder {
@@ -56,6 +63,11 @@ public final class DocIdSetBuilder {
public void add(int doc) {
bitSet.set(doc);
}
+
+ @Override
+ public void add(DocIdSetIterator iterator) throws IOException {
+ bitSet.or(iterator);
+ }
}
private static class Buffer {
diff --git a/lucene/core/src/java/org/apache/lucene/util/FixedBitSet.java b/lucene/core/src/java/org/apache/lucene/util/FixedBitSet.java
index 1e91494..d30a314 100644
--- a/lucene/core/src/java/org/apache/lucene/util/FixedBitSet.java
+++ b/lucene/core/src/java/org/apache/lucene/util/FixedBitSet.java
@@ -269,6 +269,10 @@ public final class FixedBitSet extends BitSet {
checkUnpositioned(iter);
final FixedBitSet bits = BitSetIterator.getFixedBitSetOrNull(iter);
or(bits);
+ } else if (iter instanceof DocBaseBitSetIterator) {
+ checkUnpositioned(iter);
+ DocBaseBitSetIterator baseIter = (DocBaseBitSetIterator) iter;
+ or(baseIter.getDocBase() >> 6, baseIter.getBitSet());
} else {
super.or(iter);
}
@@ -276,15 +280,20 @@ public final class FixedBitSet extends BitSet {
/** this = this OR other */
public void or(FixedBitSet other) {
- or(other.bits, other.numWords);
+ or(0, other.bits, other.numWords);
+ }
+
+ private void or(final int otherOffsetWords, FixedBitSet other) {
+ or(otherOffsetWords, other.bits, other.numWords);
}
- private void or(final long[] otherArr, final int otherNumWords) {
- assert otherNumWords <= numWords : "numWords=" + numWords + ", otherNumWords=" + otherNumWords;
+ private void or(final int otherOffsetWords, final long[] otherArr, final int otherNumWords) {
+ assert otherNumWords + otherOffsetWords <= numWords
+ : "numWords=" + numWords + ", otherNumWords=" + otherNumWords;
+ int pos = Math.min(numWords - otherOffsetWords, otherNumWords);
final long[] thisArr = this.bits;
- int pos = Math.min(numWords, otherNumWords);
while (--pos >= 0) {
- thisArr[pos] |= otherArr[pos];
+ thisArr[pos + otherOffsetWords] |= otherArr[pos];
}
}
diff --git a/lucene/core/src/java/org/apache/lucene/util/bkd/DocIdsWriter.java b/lucene/core/src/java/org/apache/lucene/util/bkd/DocIdsWriter.java
index 6be3c43..def705b 100644
--- a/lucene/core/src/java/org/apache/lucene/util/bkd/DocIdsWriter.java
+++ b/lucene/core/src/java/org/apache/lucene/util/bkd/DocIdsWriter.java
@@ -18,8 +18,11 @@ package org.apache.lucene.util.bkd;
import java.io.IOException;
import org.apache.lucene.index.PointValues.IntersectVisitor;
+import org.apache.lucene.search.DocIdSetIterator;
import org.apache.lucene.store.DataOutput;
import org.apache.lucene.store.IndexInput;
+import org.apache.lucene.util.DocBaseBitSetIterator;
+import org.apache.lucene.util.FixedBitSet;
class DocIdsWriter {
@@ -29,12 +32,26 @@ class DocIdsWriter {
// docs can be sorted either when all docs in a block have the same value
// or when a segment is sorted
boolean sorted = true;
+ boolean strictlySorted = true;
for (int i = 1; i < count; ++i) {
- if (docIds[start + i - 1] > docIds[start + i]) {
- sorted = false;
+ int last = docIds[start + i - 1];
+ int current = docIds[start + i];
+ if (last > current) {
+ sorted = strictlySorted = false;
break;
+ } else if (last == current) {
+ strictlySorted = false;
}
}
+
+ if (strictlySorted && (docIds[start + count - 1] - docIds[start] + 1) <= (count << 4)) {
+ // Only trigger this optimization when max - min + 1 <= 16 * count in order to avoid expanding
+ // too much storage.
+ // A field with lower cardinality will have higher probability to trigger this optimization.
+ out.writeByte((byte) -1);
+ writeIdsAsBitSet(docIds, start, count, out);
+ return;
+ }
if (sorted) {
out.writeByte((byte) 0);
int previous = 0;
@@ -85,10 +102,46 @@ class DocIdsWriter {
}
}
+ private static void writeIdsAsBitSet(int[] docIds, int start, int count, DataOutput out)
+ throws IOException {
+ int min = docIds[start];
+ int max = docIds[start + count - 1];
+
+ final int offsetWords = min >> 6;
+ final int offsetBits = offsetWords << 6;
+ final int totalWordCount = FixedBitSet.bits2words(max - offsetBits + 1);
+ long currentWord = 0;
+ int currentWordIndex = 0;
+
+ out.writeVInt(offsetWords);
+ out.writeVInt(totalWordCount);
+ // build bit set streaming
+ for (int i = 0; i < count; i++) {
+ final int index = docIds[start + i] - offsetBits;
+ final int nextWordIndex = index >> 6;
+ assert currentWordIndex <= nextWordIndex;
+ if (currentWordIndex < nextWordIndex) {
+ out.writeLong(currentWord);
+ currentWord = 0L;
+ currentWordIndex++;
+ while (currentWordIndex < nextWordIndex) {
+ currentWordIndex++;
+ out.writeLong(0L);
+ }
+ }
+ currentWord |= 1L << index;
+ }
+ out.writeLong(currentWord);
+ assert currentWordIndex + 1 == totalWordCount;
+ }
+
/** Read {@code count} integers into {@code docIDs}. */
static void readInts(IndexInput in, int count, int[] docIDs) throws IOException {
final int bpv = in.readByte();
switch (bpv) {
+ case -1:
+ readBitSet(in, count, docIDs);
+ break;
case 0:
readDeltaVInts(in, count, docIDs);
break;
@@ -103,6 +156,24 @@ class DocIdsWriter {
}
}
+ private static DocIdSetIterator readBitSetIterator(IndexInput in, int count) throws IOException {
+ int offsetWords = in.readVInt();
+ int longLen = in.readVInt();
+ long[] bits = new long[longLen];
+ in.readLongs(bits, 0, longLen);
+ FixedBitSet bitSet = new FixedBitSet(bits, longLen << 6);
+ return new DocBaseBitSetIterator(bitSet, count, offsetWords << 6);
+ }
+
+ private static void readBitSet(IndexInput in, int count, int[] docIDs) throws IOException {
+ DocIdSetIterator iterator = readBitSetIterator(in, count);
+ int docId, pos = 0;
+ while ((docId = iterator.nextDoc()) != DocIdSetIterator.NO_MORE_DOCS) {
+ docIDs[pos++] = docId;
+ }
+ assert pos == count : "pos: " + pos + "count: " + count;
+ }
+
private static void readDeltaVInts(IndexInput in, int count, int[] docIDs) throws IOException {
int doc = 0;
for (int i = 0; i < count; i++) {
@@ -144,6 +215,9 @@ class DocIdsWriter {
static void readInts(IndexInput in, int count, IntersectVisitor visitor) throws IOException {
final int bpv = in.readByte();
switch (bpv) {
+ case -1:
+ readBitSet(in, count, visitor);
+ break;
case 0:
readDeltaVInts(in, count, visitor);
break;
@@ -194,4 +268,10 @@ class DocIdsWriter {
visitor.visit((Short.toUnsignedInt(in.readShort()) << 8) | Byte.toUnsignedInt(in.readByte()));
}
}
+
+ private static void readBitSet(IndexInput in, int count, IntersectVisitor visitor)
+ throws IOException {
+ DocIdSetIterator bitSetIterator = readBitSetIterator(in, count);
+ visitor.visit(bitSetIterator);
+ }
}
diff --git a/lucene/core/src/test/org/apache/lucene/util/bkd/TestDocIdsWriter.java b/lucene/core/src/test/org/apache/lucene/util/bkd/TestDocIdsWriter.java
index e70de93..2473294 100644
--- a/lucene/core/src/test/org/apache/lucene/util/bkd/TestDocIdsWriter.java
+++ b/lucene/core/src/test/org/apache/lucene/util/bkd/TestDocIdsWriter.java
@@ -18,6 +18,8 @@ package org.apache.lucene.util.bkd;
import java.io.IOException;
import java.util.Arrays;
+import java.util.HashSet;
+import java.util.Set;
import org.apache.lucene.index.PointValues.IntersectVisitor;
import org.apache.lucene.index.PointValues.Relation;
import org.apache.lucene.store.Directory;
@@ -58,6 +60,22 @@ public class TestDocIdsWriter extends LuceneTestCase {
}
}
+ public void testBitSet() throws Exception {
+ int numIters = atLeast(100);
+ try (Directory dir = newDirectory()) {
+ for (int iter = 0; iter < numIters; ++iter) {
+ int size = random().nextInt(5000);
+ Set<Integer> set = new HashSet<>(size);
+ int small = random().nextInt(1000);
+ while (set.size() < size) {
+ set.add(small + random().nextInt(size * 16));
+ }
+ int[] docIDs = set.stream().mapToInt(t -> t).sorted().toArray();
+ test(dir, docIDs);
+ }
+ }
+ }
+
private void test(Directory dir, int[] ints) throws Exception {
final long len;
try (IndexOutput out = dir.createOutput("tmp", IOContext.DEFAULT)) {
diff --git a/lucene/sandbox/src/java/org/apache/lucene/sandbox/search/MultiRangeQuery.java b/lucene/sandbox/src/java/org/apache/lucene/sandbox/search/MultiRangeQuery.java
index 6e25a28..3d36420 100644
--- a/lucene/sandbox/src/java/org/apache/lucene/sandbox/search/MultiRangeQuery.java
+++ b/lucene/sandbox/src/java/org/apache/lucene/sandbox/search/MultiRangeQuery.java
@@ -194,6 +194,11 @@ public abstract class MultiRangeQuery extends Query {
}
@Override
+ public void visit(DocIdSetIterator iterator) throws IOException {
+ adder.add(iterator);
+ }
+
+ @Override
public void visit(int docID, byte[] packedValue) {
if (range.matches(packedValue)) {
adder.add(docID);
diff --git a/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/PointInShapeIntersectVisitor.java b/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/PointInShapeIntersectVisitor.java
index f33ee4f..8883fef 100644
--- a/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/PointInShapeIntersectVisitor.java
+++ b/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/PointInShapeIntersectVisitor.java
@@ -17,8 +17,10 @@
package org.apache.lucene.spatial3d;
+import java.io.IOException;
import org.apache.lucene.index.PointValues.IntersectVisitor;
import org.apache.lucene.index.PointValues.Relation;
+import org.apache.lucene.search.DocIdSetIterator;
import org.apache.lucene.spatial3d.geom.GeoArea;
import org.apache.lucene.spatial3d.geom.GeoAreaFactory;
import org.apache.lucene.spatial3d.geom.GeoShape;
@@ -61,6 +63,11 @@ class PointInShapeIntersectVisitor implements IntersectVisitor {
}
@Override
+ public void visit(DocIdSetIterator iterator) throws IOException {
+ adder.add(iterator);
+ }
+
+ @Override
public void visit(int docID, byte[] packedValue) {
assert packedValue.length == 12;
double x = Geo3DPoint.decodeDimension(packedValue, 0, shape.getPlanetModel());
[lucene] 02/02: LUCENE-10278: don't write zero-sized array in this test (#501)
Posted by jp...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
jpountz pushed a commit to branch branch_9x
in repository https://gitbox.apache.org/repos/asf/lucene.git
commit cbd306f87b1dd8da37c862b73e23a5195737d16c
Author: Robert Muir <rm...@apache.org>
AuthorDate: Thu Dec 2 09:53:09 2021 -0500
LUCENE-10278: don't write zero-sized array in this test (#501)
DocIdsWriter is not prepared for this.
---
.../core/src/test/org/apache/lucene/util/bkd/TestDocIdsWriter.java | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/lucene/core/src/test/org/apache/lucene/util/bkd/TestDocIdsWriter.java b/lucene/core/src/test/org/apache/lucene/util/bkd/TestDocIdsWriter.java
index 2473294..d2115c8 100644
--- a/lucene/core/src/test/org/apache/lucene/util/bkd/TestDocIdsWriter.java
+++ b/lucene/core/src/test/org/apache/lucene/util/bkd/TestDocIdsWriter.java
@@ -35,7 +35,7 @@ public class TestDocIdsWriter extends LuceneTestCase {
int numIters = atLeast(100);
try (Directory dir = newDirectory()) {
for (int iter = 0; iter < numIters; ++iter) {
- int[] docIDs = new int[random().nextInt(5000)];
+ int[] docIDs = new int[1 + random().nextInt(5000)];
final int bpv = TestUtil.nextInt(random(), 1, 32);
for (int i = 0; i < docIDs.length; ++i) {
docIDs[i] = TestUtil.nextInt(random(), 0, (1 << bpv) - 1);
@@ -49,7 +49,7 @@ public class TestDocIdsWriter extends LuceneTestCase {
int numIters = atLeast(100);
try (Directory dir = newDirectory()) {
for (int iter = 0; iter < numIters; ++iter) {
- int[] docIDs = new int[random().nextInt(5000)];
+ int[] docIDs = new int[1 + random().nextInt(5000)];
final int bpv = TestUtil.nextInt(random(), 1, 32);
for (int i = 0; i < docIDs.length; ++i) {
docIDs[i] = TestUtil.nextInt(random(), 0, (1 << bpv) - 1);
@@ -64,7 +64,7 @@ public class TestDocIdsWriter extends LuceneTestCase {
int numIters = atLeast(100);
try (Directory dir = newDirectory()) {
for (int iter = 0; iter < numIters; ++iter) {
- int size = random().nextInt(5000);
+ int size = 1 + random().nextInt(5000);
Set<Integer> set = new HashSet<>(size);
int small = random().nextInt(1000);
while (set.size() < size) {