You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by rm...@apache.org on 2016/03/09 17:26:06 UTC
lucene-solr git commit: LUCENE-7079: add newSetQuery(String,
Collection) to primitive Point types
Repository: lucene-solr
Updated Branches:
refs/heads/master dacbf333e -> 58623e00c
LUCENE-7079: add newSetQuery(String, Collection) to primitive Point types
Project: http://git-wip-us.apache.org/repos/asf/lucene-solr/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucene-solr/commit/58623e00
Tree: http://git-wip-us.apache.org/repos/asf/lucene-solr/tree/58623e00
Diff: http://git-wip-us.apache.org/repos/asf/lucene-solr/diff/58623e00
Branch: refs/heads/master
Commit: 58623e00ccd5ff4a6b97ad9c518fd597d9abdfda
Parents: dacbf33
Author: Robert Muir <rm...@apache.org>
Authored: Wed Mar 9 11:25:37 2016 -0500
Committer: Robert Muir <rm...@apache.org>
Committed: Wed Mar 9 11:25:37 2016 -0500
----------------------------------------------------------------------
.../org/apache/lucene/document/DoublePoint.java | 16 ++++++++++++++++
.../java/org/apache/lucene/document/FloatPoint.java | 16 ++++++++++++++++
.../java/org/apache/lucene/document/IntPoint.java | 16 ++++++++++++++++
.../java/org/apache/lucene/document/LongPoint.java | 16 ++++++++++++++++
.../org/apache/lucene/search/TestPointQueries.java | 8 ++++++++
.../apache/lucene/search/join/TestBlockJoin.java | 7 +------
6 files changed, 73 insertions(+), 6 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/58623e00/lucene/core/src/java/org/apache/lucene/document/DoublePoint.java
----------------------------------------------------------------------
diff --git a/lucene/core/src/java/org/apache/lucene/document/DoublePoint.java b/lucene/core/src/java/org/apache/lucene/document/DoublePoint.java
index 26ac0ce..1133b22 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);
+ }
}
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/58623e00/lucene/core/src/java/org/apache/lucene/document/FloatPoint.java
----------------------------------------------------------------------
diff --git a/lucene/core/src/java/org/apache/lucene/document/FloatPoint.java b/lucene/core/src/java/org/apache/lucene/document/FloatPoint.java
index c58881e..3d110db 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);
+ }
}
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/58623e00/lucene/core/src/java/org/apache/lucene/document/IntPoint.java
----------------------------------------------------------------------
diff --git a/lucene/core/src/java/org/apache/lucene/document/IntPoint.java b/lucene/core/src/java/org/apache/lucene/document/IntPoint.java
index cb8315f..53ae3d3 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);
+ }
}
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/58623e00/lucene/core/src/java/org/apache/lucene/document/LongPoint.java
----------------------------------------------------------------------
diff --git a/lucene/core/src/java/org/apache/lucene/document/LongPoint.java b/lucene/core/src/java/org/apache/lucene/document/LongPoint.java
index ff78132..c4fd887 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);
+ }
}
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/58623e00/lucene/core/src/test/org/apache/lucene/search/TestPointQueries.java
----------------------------------------------------------------------
diff --git a/lucene/core/src/test/org/apache/lucene/search/TestPointQueries.java b/lucene/core/src/test/org/apache/lucene/search/TestPointQueries.java
index 4d9aa59..c72ab44 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();
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/58623e00/lucene/join/src/test/org/apache/lucene/search/join/TestBlockJoin.java
----------------------------------------------------------------------
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.java
index b5f2038..9c39299 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);
}