You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by mi...@apache.org on 2016/02/25 19:42:01 UTC
[08/18] lucene-solr git commit: add newSetQuery to DoublePoint and
FloatPoint
add newSetQuery to DoublePoint and FloatPoint
Project: http://git-wip-us.apache.org/repos/asf/lucene-solr/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucene-solr/commit/30fcafdf
Tree: http://git-wip-us.apache.org/repos/asf/lucene-solr/tree/30fcafdf
Diff: http://git-wip-us.apache.org/repos/asf/lucene-solr/diff/30fcafdf
Branch: refs/heads/master
Commit: 30fcafdfd944c97f5c1fdaa9a310f04e7c1b2f2e
Parents: 79c8bce
Author: Mike McCandless <mi...@apache.org>
Authored: Wed Feb 24 08:48:10 2016 -0500
Committer: Mike McCandless <mi...@apache.org>
Committed: Wed Feb 24 08:48:10 2016 -0500
----------------------------------------------------------------------
.../org/apache/lucene/document/DoublePoint.java | 44 ++++++++++
.../org/apache/lucene/document/FloatPoint.java | 47 +++++++++++
.../org/apache/lucene/document/IntPoint.java | 5 +-
.../org/apache/lucene/document/LongPoint.java | 5 +-
.../apache/lucene/search/TestPointQueries.java | 86 ++++++++++++++++++--
.../apache/lucene/document/BigIntegerPoint.java | 2 +
.../lucene/document/InetAddressPoint.java | 2 +
.../org/apache/lucene/document/LatLonPoint.java | 2 +
8 files changed, 180 insertions(+), 13 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/30fcafdf/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 ee0d6f2..53973c9 100644
--- a/lucene/core/src/java/org/apache/lucene/document/DoublePoint.java
+++ b/lucene/core/src/java/org/apache/lucene/document/DoublePoint.java
@@ -16,8 +16,13 @@
*/
package org.apache.lucene.document;
+import java.io.IOException;
+import java.util.Arrays;
+
+import org.apache.lucene.search.PointInSetQuery;
import org.apache.lucene.search.PointRangeQuery;
import org.apache.lucene.util.BytesRef;
+import org.apache.lucene.util.BytesRefIterator;
import org.apache.lucene.util.NumericUtils;
/**
@@ -212,4 +217,43 @@ 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 valuesIn all int values to match
+ */
+ public static Query newSetQuery(String field, double... valuesIn) throws IOException {
+
+ // Don't unexpectedly change the user's incoming values array:
+ double[] values = valuesIn.clone();
+
+ Arrays.sort(values);
+
+ final BytesRef value = new BytesRef(new byte[Double.BYTES]);
+
+ return new PointInSetQuery(field, 1, Double.BYTES,
+ new BytesRefIterator() {
+
+ int upto;
+
+ @Override
+ public BytesRef next() {
+ if (upto == values.length) {
+ return null;
+ } else {
+ encodeDimension(values[upto], value.bytes, 0);
+ upto++;
+ return value;
+ }
+ }
+ }) {
+ @Override
+ protected String toString(byte[] value) {
+ assert value.length == Double.BYTES;
+ return Double.toString(decodeDimension(value, 0));
+ }
+ };
+ }
}
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/30fcafdf/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 34216b4..d262c18 100644
--- a/lucene/core/src/java/org/apache/lucene/document/FloatPoint.java
+++ b/lucene/core/src/java/org/apache/lucene/document/FloatPoint.java
@@ -16,8 +16,13 @@
*/
package org.apache.lucene.document;
+import java.io.IOException;
+import java.util.Arrays;
+
+import org.apache.lucene.search.PointInSetQuery;
import org.apache.lucene.search.PointRangeQuery;
import org.apache.lucene.util.BytesRef;
+import org.apache.lucene.util.BytesRefIterator;
import org.apache.lucene.util.NumericUtils;
/**
@@ -212,4 +217,46 @@ 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 valuesIn all int values to match
+ */
+ public static Query newSetQuery(String field, float... valuesIn) throws IOException {
+
+ // Don't unexpectedly change the user's incoming values array:
+ float[] values = valuesIn.clone();
+
+ Arrays.sort(values);
+
+ System.out.println("VALUES: " + Arrays.toString(values));
+
+ final BytesRef value = new BytesRef(new byte[Float.BYTES]);
+
+ return new PointInSetQuery(field, 1, Float.BYTES,
+ new BytesRefIterator() {
+
+ int upto;
+
+ @Override
+ public BytesRef next() {
+ if (upto == values.length) {
+ return null;
+ } else {
+ encodeDimension(values[upto], value.bytes, 0);
+ upto++;
+ System.out.println("ret: " + value);
+ return value;
+ }
+ }
+ }) {
+ @Override
+ protected String toString(byte[] value) {
+ assert value.length == Float.BYTES;
+ return Float.toString(decodeDimension(value, 0));
+ }
+ };
+ }
}
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/30fcafdf/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 2b255d7..cdd10c7 100644
--- a/lucene/core/src/java/org/apache/lucene/document/IntPoint.java
+++ b/lucene/core/src/java/org/apache/lucene/document/IntPoint.java
@@ -224,7 +224,7 @@ public final class IntPoint extends Field {
* @param field field name. must not be {@code null}.
* @param valuesIn all int values to match
*/
- public static PointInSetQuery newSetQuery(String field, int... valuesIn) throws IOException {
+ public static Query newSetQuery(String field, int... valuesIn) throws IOException {
// Don't unexpectedly change the user's incoming values array:
int[] values = valuesIn.clone();
@@ -232,7 +232,6 @@ public final class IntPoint extends Field {
Arrays.sort(values);
final BytesRef value = new BytesRef(new byte[Integer.BYTES]);
- value.length = Integer.BYTES;
return new PointInSetQuery(field, 1, Integer.BYTES,
new BytesRefIterator() {
@@ -244,7 +243,7 @@ public final class IntPoint extends Field {
if (upto == values.length) {
return null;
} else {
- IntPoint.encodeDimension(values[upto], value.bytes, 0);
+ encodeDimension(values[upto], value.bytes, 0);
upto++;
return value;
}
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/30fcafdf/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 16f7e6c..9c0ba3f 100644
--- a/lucene/core/src/java/org/apache/lucene/document/LongPoint.java
+++ b/lucene/core/src/java/org/apache/lucene/document/LongPoint.java
@@ -224,7 +224,7 @@ public final class LongPoint extends Field {
* @param field field name. must not be {@code null}.
* @param valuesIn all int values to match
*/
- public static PointInSetQuery newSetQuery(String field, long... valuesIn) throws IOException {
+ public static Query newSetQuery(String field, long... valuesIn) throws IOException {
// Don't unexpectedly change the user's incoming values array:
long[] values = valuesIn.clone();
@@ -232,7 +232,6 @@ public final class LongPoint extends Field {
Arrays.sort(values);
final BytesRef value = new BytesRef(new byte[Long.BYTES]);
- value.length = Long.BYTES;
return new PointInSetQuery(field, 1, Long.BYTES,
new BytesRefIterator() {
@@ -244,7 +243,7 @@ public final class LongPoint extends Field {
if (upto == values.length) {
return null;
} else {
- LongPoint.encodeDimension(values[upto], value.bytes, 0);
+ encodeDimension(values[upto], value.bytes, 0);
upto++;
return value;
}
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/30fcafdf/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 843a929..e439cc7 100644
--- a/lucene/core/src/test/org/apache/lucene/search/TestPointQueries.java
+++ b/lucene/core/src/test/org/apache/lucene/search/TestPointQueries.java
@@ -1270,17 +1270,23 @@ public class TestPointQueries extends LuceneTestCase {
Document doc = new Document();
doc.add(new IntPoint("int", 17));
- doc.add(new LongPoint("long", 17));
+ doc.add(new LongPoint("long", 17L));
+ doc.add(new FloatPoint("float", 17.0f));
+ doc.add(new DoublePoint("double", 17.0));
w.addDocument(doc);
doc = new Document();
doc.add(new IntPoint("int", 42));
- doc.add(new LongPoint("long", 42));
+ doc.add(new LongPoint("long", 42L));
+ doc.add(new FloatPoint("float", 42.0f));
+ doc.add(new DoublePoint("double", 42.0));
w.addDocument(doc);
doc = new Document();
doc.add(new IntPoint("int", 97));
- doc.add(new LongPoint("long", 97));
+ doc.add(new LongPoint("long", 97L));
+ doc.add(new FloatPoint("float", 97.0f));
+ doc.add(new DoublePoint("double", 97.0));
w.addDocument(doc);
IndexReader r = DirectoryReader.open(w);
@@ -1299,6 +1305,20 @@ public class TestPointQueries extends LuceneTestCase {
assertEquals(3, s.count(LongPoint.newSetQuery("long", 17, 20, 42, 97)));
assertEquals(3, s.count(LongPoint.newSetQuery("long", 17, 105, 42, 97)));
+ assertEquals(0, s.count(LongPoint.newSetQuery("float", 16)));
+ assertEquals(1, s.count(LongPoint.newSetQuery("float", 17)));
+ assertEquals(3, s.count(LongPoint.newSetQuery("float", 17, 97, 42)));
+ assertEquals(3, s.count(LongPoint.newSetQuery("float", -7, 17, 42, 97)));
+ assertEquals(3, s.count(LongPoint.newSetQuery("float", 17, 20, 42, 97)));
+ assertEquals(3, s.count(LongPoint.newSetQuery("float", 17, 105, 42, 97)));
+
+ assertEquals(0, s.count(LongPoint.newSetQuery("double", 16)));
+ assertEquals(1, s.count(LongPoint.newSetQuery("double", 17)));
+ assertEquals(3, s.count(LongPoint.newSetQuery("double", 17, 97, 42)));
+ assertEquals(3, s.count(LongPoint.newSetQuery("double", -7, 17, 42, 97)));
+ assertEquals(3, s.count(LongPoint.newSetQuery("double", 17, 20, 42, 97)));
+ assertEquals(3, s.count(LongPoint.newSetQuery("double", 17, 105, 42, 97)));
+
w.close();
r.close();
dir.close();
@@ -1313,8 +1333,12 @@ public class TestPointQueries extends LuceneTestCase {
Document doc = new Document();
doc.add(new IntPoint("int", 17));
doc.add(new IntPoint("int", 42));
- doc.add(new LongPoint("long", 17));
- doc.add(new LongPoint("long", 42));
+ doc.add(new LongPoint("long", 17L));
+ doc.add(new LongPoint("long", 42L));
+ doc.add(new FloatPoint("float", 17.0f));
+ doc.add(new FloatPoint("float", 42.0f));
+ doc.add(new DoublePoint("double", 17.0));
+ doc.add(new DoublePoint("double", 42.0));
w.addDocument(doc);
IndexReader r = DirectoryReader.open(w);
@@ -1331,6 +1355,18 @@ public class TestPointQueries extends LuceneTestCase {
assertEquals(1, s.count(LongPoint.newSetQuery("long", -7, 17, 42, 97)));
assertEquals(0, s.count(LongPoint.newSetQuery("long", 16, 20, 41, 97)));
+ assertEquals(0, s.count(FloatPoint.newSetQuery("float", 16)));
+ assertEquals(1, s.count(FloatPoint.newSetQuery("float", 17)));
+ assertEquals(1, s.count(FloatPoint.newSetQuery("float", 17, 97, 42)));
+ assertEquals(1, s.count(FloatPoint.newSetQuery("float", -7, 17, 42, 97)));
+ assertEquals(0, s.count(FloatPoint.newSetQuery("float", 16, 20, 41, 97)));
+
+ assertEquals(0, s.count(DoublePoint.newSetQuery("double", 16)));
+ assertEquals(1, s.count(DoublePoint.newSetQuery("double", 17)));
+ assertEquals(1, s.count(DoublePoint.newSetQuery("double", 17, 97, 42)));
+ assertEquals(1, s.count(DoublePoint.newSetQuery("double", -7, 17, 42, 97)));
+ assertEquals(0, s.count(DoublePoint.newSetQuery("double", 16, 20, 41, 97)));
+
w.close();
r.close();
dir.close();
@@ -1350,7 +1386,9 @@ public class TestPointQueries extends LuceneTestCase {
}
Document doc = new Document();
doc.add(new IntPoint("int", x));
- doc.add(new LongPoint("long", x));
+ doc.add(new LongPoint("long", (long) x));
+ doc.add(new FloatPoint("float", (float) x));
+ doc.add(new DoublePoint("double", (double) x));
w.addDocument(doc);
}
@@ -1367,6 +1405,19 @@ public class TestPointQueries extends LuceneTestCase {
assertEquals(zeroCount, s.count(LongPoint.newSetQuery("long", 7, 0)));
assertEquals(10000-zeroCount, s.count(LongPoint.newSetQuery("long", 1)));
assertEquals(0, s.count(LongPoint.newSetQuery("long", 2)));
+
+ assertEquals(zeroCount, s.count(FloatPoint.newSetQuery("float", 0)));
+ assertEquals(zeroCount, s.count(FloatPoint.newSetQuery("float", 0, -7)));
+ assertEquals(zeroCount, s.count(FloatPoint.newSetQuery("float", 7, 0)));
+ assertEquals(10000-zeroCount, s.count(FloatPoint.newSetQuery("float", 1)));
+ assertEquals(0, s.count(FloatPoint.newSetQuery("float", 2)));
+
+ assertEquals(zeroCount, s.count(DoublePoint.newSetQuery("double", 0)));
+ assertEquals(zeroCount, s.count(DoublePoint.newSetQuery("double", 0, -7)));
+ assertEquals(zeroCount, s.count(DoublePoint.newSetQuery("double", 7, 0)));
+ assertEquals(10000-zeroCount, s.count(DoublePoint.newSetQuery("double", 1)));
+ assertEquals(0, s.count(DoublePoint.newSetQuery("double", 2)));
+
w.close();
r.close();
dir.close();
@@ -1386,7 +1437,9 @@ public class TestPointQueries extends LuceneTestCase {
}
Document doc = new Document();
doc.add(new IntPoint("int", x));
- doc.add(new LongPoint("long", x));
+ doc.add(new LongPoint("long", (long) x));
+ doc.add(new FloatPoint("float", (float) x));
+ doc.add(new DoublePoint("double", (double) x));
w.addDocument(doc);
}
@@ -1403,6 +1456,19 @@ public class TestPointQueries extends LuceneTestCase {
assertEquals(zeroCount, s.count(LongPoint.newSetQuery("long", 7, 0)));
assertEquals(10000-zeroCount, s.count(LongPoint.newSetQuery("long", 200)));
assertEquals(0, s.count(LongPoint.newSetQuery("long", 2)));
+
+ assertEquals(zeroCount, s.count(FloatPoint.newSetQuery("float", 0)));
+ assertEquals(zeroCount, s.count(FloatPoint.newSetQuery("float", 0, -7)));
+ assertEquals(zeroCount, s.count(FloatPoint.newSetQuery("float", 7, 0)));
+ assertEquals(10000-zeroCount, s.count(FloatPoint.newSetQuery("float", 200)));
+ assertEquals(0, s.count(FloatPoint.newSetQuery("float", 2)));
+
+ assertEquals(zeroCount, s.count(DoublePoint.newSetQuery("double", 0)));
+ assertEquals(zeroCount, s.count(DoublePoint.newSetQuery("double", 0, -7)));
+ assertEquals(zeroCount, s.count(DoublePoint.newSetQuery("double", 7, 0)));
+ assertEquals(10000-zeroCount, s.count(DoublePoint.newSetQuery("double", 200)));
+ assertEquals(0, s.count(DoublePoint.newSetQuery("double", 2)));
+
w.close();
r.close();
dir.close();
@@ -1428,5 +1494,11 @@ public class TestPointQueries extends LuceneTestCase {
// long
assertEquals("long:{-42 18}", LongPoint.newSetQuery("long", -42L, 18L).toString());
+
+ // float
+ assertEquals("float:{-42.0 18.0}", FloatPoint.newSetQuery("float", -42.0f, 18.0f).toString());
+
+ // double
+ assertEquals("double:{-42.0 18.0}", DoublePoint.newSetQuery("double", -42.0, 18.0).toString());
}
}
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/30fcafdf/lucene/sandbox/src/java/org/apache/lucene/document/BigIntegerPoint.java
----------------------------------------------------------------------
diff --git a/lucene/sandbox/src/java/org/apache/lucene/document/BigIntegerPoint.java b/lucene/sandbox/src/java/org/apache/lucene/document/BigIntegerPoint.java
index f88c85a..6e1c6ac 100644
--- a/lucene/sandbox/src/java/org/apache/lucene/document/BigIntegerPoint.java
+++ b/lucene/sandbox/src/java/org/apache/lucene/document/BigIntegerPoint.java
@@ -212,4 +212,6 @@ public class BigIntegerPoint extends Field {
}
};
}
+
+ // nocommit newSetQuery
}
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/30fcafdf/lucene/sandbox/src/java/org/apache/lucene/document/InetAddressPoint.java
----------------------------------------------------------------------
diff --git a/lucene/sandbox/src/java/org/apache/lucene/document/InetAddressPoint.java b/lucene/sandbox/src/java/org/apache/lucene/document/InetAddressPoint.java
index 51ada8f..10abfdd 100644
--- a/lucene/sandbox/src/java/org/apache/lucene/document/InetAddressPoint.java
+++ b/lucene/sandbox/src/java/org/apache/lucene/document/InetAddressPoint.java
@@ -205,4 +205,6 @@ public class InetAddressPoint extends Field {
}
};
}
+
+ // nocommit newSetQuery
}
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/30fcafdf/lucene/sandbox/src/java/org/apache/lucene/document/LatLonPoint.java
----------------------------------------------------------------------
diff --git a/lucene/sandbox/src/java/org/apache/lucene/document/LatLonPoint.java b/lucene/sandbox/src/java/org/apache/lucene/document/LatLonPoint.java
index 539987c..9e18c19 100644
--- a/lucene/sandbox/src/java/org/apache/lucene/document/LatLonPoint.java
+++ b/lucene/sandbox/src/java/org/apache/lucene/document/LatLonPoint.java
@@ -83,4 +83,6 @@ public class LatLonPoint extends Field {
public static double decodeLon(int x) {
return x / LON_SCALE;
}
+
+ // nocommit newSetQuery
}