Apache Solr open-source search software
LUCENE-7079: add newSetQuery(String, Collection) to primitive Point types
Robert Muir58623e00ccd5
diff --git a/lucene/core/src/java/org/apache/lucene/document/DoublePoint.java b/lucene/core/src/java/org/apache/lucene/document/DoublePoint.javaindex 26ac0ced6f1..1133b221393 100644--- a/lucene/core/src/java/org/apache/lucene/document/DoublePoint.java+++ b/lucene/core/src/java/org/apache/lucene/document/DoublePoint.java@@ -17,6 +17,7 @@package org.apache.lucene.document;import java.util.Arrays;+import java.util.Collection;import org.apache.lucene.index.PointValues;import org.apache.lucene.search.PointInSetQuery;@@ -247,4 +248,19 @@ public final class DoublePoint extends Field {}};}++ /**+ * Create a query matching any of the specified 1D values. This is the points equivalent of {@code TermsQuery}.+ *+ * @param field field name. must not be {@code null}.+ * @param values all values to match+ */+ public static Query newSetQuery(String field, Collection<Double> values) {+ Double[] boxed = values.toArray(new Double[0]);+ double[] unboxed = new double[boxed.length];+ for (int i = 0; i < boxed.length; i++) {+ unboxed[i] = boxed[i];+ }+ return newSetQuery(field, unboxed);+ }}diff --git a/lucene/core/src/java/org/apache/lucene/document/FloatPoint.java b/lucene/core/src/java/org/apache/lucene/document/FloatPoint.javaindex c58881ec880..3d110db2cd8 100644--- a/lucene/core/src/java/org/apache/lucene/document/FloatPoint.java+++ b/lucene/core/src/java/org/apache/lucene/document/FloatPoint.java@@ -17,6 +17,7 @@package org.apache.lucene.document;import java.util.Arrays;+import java.util.Collection;import org.apache.lucene.index.PointValues;import org.apache.lucene.search.PointInSetQuery;@@ -247,4 +248,19 @@ public final class FloatPoint extends Field {}};}++ /**+ * Create a query matching any of the specified 1D values. This is the points equivalent of {@code TermsQuery}.+ *+ * @param field field name. must not be {@code null}.+ * @param values all values to match+ */+ public static Query newSetQuery(String field, Collection<Float> values) {+ Float[] boxed = values.toArray(new Float[0]);+ float[] unboxed = new float[boxed.length];+ for (int i = 0; i < boxed.length; i++) {+ unboxed[i] = boxed[i];+ }+ return newSetQuery(field, unboxed);+ }}diff --git a/lucene/core/src/java/org/apache/lucene/document/IntPoint.java b/lucene/core/src/java/org/apache/lucene/document/IntPoint.javaindex cb8315f2f20..53ae3d3dd2a 100644--- a/lucene/core/src/java/org/apache/lucene/document/IntPoint.java+++ b/lucene/core/src/java/org/apache/lucene/document/IntPoint.java@@ -17,6 +17,7 @@package org.apache.lucene.document;import java.util.Arrays;+import java.util.Collection;import org.apache.lucene.index.PointValues;import org.apache.lucene.search.PointInSetQuery;@@ -247,4 +248,19 @@ public final class IntPoint extends Field {}};}++ /**+ * Create a query matching any of the specified 1D values. This is the points equivalent of {@code TermsQuery}.+ *+ * @param field field name. must not be {@code null}.+ * @param values all values to match+ */+ public static Query newSetQuery(String field, Collection<Integer> values) {+ Integer[] boxed = values.toArray(new Integer[0]);+ int[] unboxed = new int[boxed.length];+ for (int i = 0; i < boxed.length; i++) {+ unboxed[i] = boxed[i];+ }+ return newSetQuery(field, unboxed);+ }}diff --git a/lucene/core/src/java/org/apache/lucene/document/LongPoint.java b/lucene/core/src/java/org/apache/lucene/document/LongPoint.javaindex ff78132d7b6..c4fd8875205 100644--- a/lucene/core/src/java/org/apache/lucene/document/LongPoint.java+++ b/lucene/core/src/java/org/apache/lucene/document/LongPoint.java@@ -17,6 +17,7 @@package org.apache.lucene.document;import java.util.Arrays;+import java.util.Collection;import org.apache.lucene.index.PointValues;import org.apache.lucene.search.PointInSetQuery;@@ -247,4 +248,19 @@ public final class LongPoint extends Field {}};}++ /**+ * Create a query matching any of the specified 1D values. This is the points equivalent of {@code TermsQuery}.+ *+ * @param field field name. must not be {@code null}.+ * @param values all values to match+ */+ public static Query newSetQuery(String field, Collection<Long> values) {+ Long[] boxed = values.toArray(new Long[0]);+ long[] unboxed = new long[boxed.length];+ for (int i = 0; i < boxed.length; i++) {+ unboxed[i] = boxed[i];+ }+ return newSetQuery(field, unboxed);+ }}diff --git a/lucene/core/src/test/org/apache/lucene/search/TestPointQueries.java b/lucene/core/src/test/org/apache/lucene/search/TestPointQueries.javaindex 4d9aa593f06..c72ab44ac39 100644--- a/lucene/core/src/test/org/apache/lucene/search/TestPointQueries.java+++ b/lucene/core/src/test/org/apache/lucene/search/TestPointQueries.java@@ -1602,6 +1602,14 @@ public class TestPointQueries extends LuceneTestCase {r.close();dir.close();}++ /** Boxed methods for primitive types should behave the same as unboxed: just sugar */+ public void testPointIntSetBoxed() throws Exception {+ assertEquals(IntPoint.newSetQuery("foo", 1, 2, 3), IntPoint.newSetQuery("foo", Arrays.asList(1, 2, 3)));+ assertEquals(FloatPoint.newSetQuery("foo", 1F, 2F, 3F), FloatPoint.newSetQuery("foo", Arrays.asList(1F, 2F, 3F)));+ assertEquals(LongPoint.newSetQuery("foo", 1L, 2L, 3L), LongPoint.newSetQuery("foo", Arrays.asList(1L, 2L, 3L)));+ assertEquals(DoublePoint.newSetQuery("foo", 1D, 2D, 3D), DoublePoint.newSetQuery("foo", Arrays.asList(1D, 2D, 3D)));+ }public void testBasicMultiValuedPointInSetQuery() throws Exception {Directory dir = newDirectory();diff --git a/lucene/join/src/test/org/apache/lucene/search/join/TestBlockJoin.java b/lucene/join/src/test/org/apache/lucene/search/join/TestBlockJoin.javaindex b5f2038a0dc..9c39299c4b4 100644--- a/lucene/join/src/test/org/apache/lucene/search/join/TestBlockJoin.java+++ b/lucene/join/src/test/org/apache/lucene/search/join/TestBlockJoin.java@@ -615,12 +615,7 @@ public class TestBlockJoin extends LuceneTestCase {}if (!toDelete.isEmpty()) {- // TODO: we should add newSetQuery(String, Collection<T>) ? this is awkward.- int[] array = new int[toDelete.size()];- for (int i = 0; i < toDelete.size(); i++) {- array[i] = toDelete.get(i);- }- Query query = IntPoint.newSetQuery("blockID", array);+ Query query = IntPoint.newSetQuery("blockID", toDelete);w.deleteDocuments(query);joinW.deleteDocuments(query);}