You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by mv...@apache.org on 2016/06/02 13:07:55 UTC

[2/2] lucene-solr:branch_6x: LUCENE-7307: Add getters to the PointInSetQuery and PointRangeQuery queries.

LUCENE-7307: Add getters to the PointInSetQuery and PointRangeQuery queries.


Project: http://git-wip-us.apache.org/repos/asf/lucene-solr/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucene-solr/commit/50feae82
Tree: http://git-wip-us.apache.org/repos/asf/lucene-solr/tree/50feae82
Diff: http://git-wip-us.apache.org/repos/asf/lucene-solr/diff/50feae82

Branch: refs/heads/branch_6x
Commit: 50feae82af5d297b720a98db07ab43e093e788b8
Parents: 734dcb9
Author: Martijn van Groningen <mv...@apache.org>
Authored: Wed Jun 1 11:42:00 2016 +0200
Committer: Martijn van Groningen <mv...@apache.org>
Committed: Thu Jun 2 15:06:20 2016 +0200

----------------------------------------------------------------------
 lucene/CHANGES.txt                              |  3 ++
 .../apache/lucene/search/PointInSetQuery.java   | 57 ++++++++++++++++++++
 .../apache/lucene/search/PointRangeQuery.java   | 20 +++++++
 .../apache/lucene/search/TestPointQueries.java  | 21 ++++++++
 4 files changed, 101 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/50feae82/lucene/CHANGES.txt
----------------------------------------------------------------------
diff --git a/lucene/CHANGES.txt b/lucene/CHANGES.txt
index ec0b8f9..83de9ed 100644
--- a/lucene/CHANGES.txt
+++ b/lucene/CHANGES.txt
@@ -168,6 +168,9 @@ Other
 * LUCENE-7206: Improve the ToParentBlockJoinQuery's explain by including the explain
   of the best matching child doc. (Ilya Kasnacheev, Jeff Evans via Martijn van Groningen)
 
+* LUCENE-7307: Add getters to the PointInSetQuery and PointRangeQuery queries.
+  (Martijn van Groningen, Adrien Grand)
+
 Build
 
 * LUCENE-7292: Use '-release' instead of '-source/-target' during

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/50feae82/lucene/core/src/java/org/apache/lucene/search/PointInSetQuery.java
----------------------------------------------------------------------
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 c19e457..e1a2c18 100644
--- a/lucene/core/src/java/org/apache/lucene/search/PointInSetQuery.java
+++ b/lucene/core/src/java/org/apache/lucene/search/PointInSetQuery.java
@@ -17,7 +17,15 @@
 package org.apache.lucene.search;
 
 import java.io.IOException;
+import java.util.AbstractCollection;
+import java.util.ArrayList;
 import java.util.Arrays;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Iterator;
+import java.util.List;
+import java.util.NoSuchElementException;
+import java.util.Set;
 
 import org.apache.lucene.document.IntPoint;
 import org.apache.lucene.index.FieldInfo;
@@ -28,6 +36,7 @@ import org.apache.lucene.index.PointValues.Relation;
 import org.apache.lucene.index.PointValues;
 import org.apache.lucene.index.PrefixCodedTerms.TermIterator;
 import org.apache.lucene.index.PrefixCodedTerms;
+import org.apache.lucene.index.Term;
 import org.apache.lucene.util.BytesRef;
 import org.apache.lucene.util.BytesRefBuilder;
 import org.apache.lucene.util.BytesRefIterator;
@@ -303,6 +312,54 @@ public abstract class PointInSetQuery extends Query {
     }
   }
 
+  public Collection<byte[]> getPackedPoints() {
+    return new AbstractCollection<byte[]>() {
+
+      @Override
+      public Iterator<byte[]> iterator() {
+        int size = (int) sortedPackedPoints.size();
+        PrefixCodedTerms.TermIterator iterator = sortedPackedPoints.iterator();
+        return new Iterator<byte[]>() {
+
+          int upto = 0;
+
+          @Override
+          public boolean hasNext() {
+            return upto < size;
+          }
+
+          @Override
+          public byte[] next() {
+            if (upto == size) {
+              throw new NoSuchElementException();
+            }
+
+            upto++;
+            BytesRef next = iterator.next();
+            return Arrays.copyOfRange(next.bytes, next.offset, next.length);
+          }
+        };
+      }
+
+      @Override
+      public int size() {
+        return (int) sortedPackedPoints.size();
+      }
+    };
+  }
+
+  public String getField() {
+    return field;
+  }
+
+  public int getNumDims() {
+    return numDims;
+  }
+
+  public int getBytesPerDim() {
+    return bytesPerDim;
+  }
+
   @Override
   public final int hashCode() {
     int hash = classHash();

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/50feae82/lucene/core/src/java/org/apache/lucene/search/PointRangeQuery.java
----------------------------------------------------------------------
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 fb7051d..63de04c 100644
--- a/lucene/core/src/java/org/apache/lucene/search/PointRangeQuery.java
+++ b/lucene/core/src/java/org/apache/lucene/search/PointRangeQuery.java
@@ -218,6 +218,26 @@ public abstract class PointRangeQuery extends Query {
     };
   }
 
+  public String getField() {
+    return field;
+  }
+
+  public int getNumDims() {
+    return numDims;
+  }
+
+  public int getBytesPerDim() {
+    return bytesPerDim;
+  }
+
+  public byte[] getLowerPoint() {
+    return lowerPoint.clone();
+  }
+
+  public byte[] getUpperPoint() {
+    return upperPoint.clone();
+  }
+
   @Override
   public final int hashCode() {
     int hash = classHash();

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/50feae82/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 88d89d2..df89e8b 100644
--- a/lucene/core/src/test/org/apache/lucene/search/TestPointQueries.java
+++ b/lucene/core/src/test/org/apache/lucene/search/TestPointQueries.java
@@ -22,9 +22,12 @@ import java.nio.charset.StandardCharsets;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.BitSet;
+import java.util.Collection;
 import java.util.Comparator;
 import java.util.HashSet;
+import java.util.Iterator;
 import java.util.List;
+import java.util.NoSuchElementException;
 import java.util.Set;
 import java.util.concurrent.CountDownLatch;
 import java.util.concurrent.atomic.AtomicBoolean;
@@ -1854,6 +1857,24 @@ public class TestPointQueries extends LuceneTestCase {
     assertEquals("bytes:{[12] [2a]}", BinaryPoint.newSetQuery("bytes", new byte[] {42}, new byte[] {18}).toString());
   }
 
+  public void testPointInSetQueryGetPackedPoints() throws Exception {
+    int numValues = randomIntValue(1, 32);
+    List<byte[]> values = new ArrayList<>(numValues);
+    for (byte i = 0; i < numValues; i++) {
+      values.add(new byte[]{i});
+    }
+
+    PointInSetQuery query = (PointInSetQuery) BinaryPoint.newSetQuery("field", values.toArray(new byte[][]{}));
+    Collection<byte[]> packedPoints = query.getPackedPoints();
+    assertEquals(numValues, packedPoints.size());
+    Iterator<byte[]> iterator = packedPoints.iterator();
+    for (byte[] expectedValue : values) {
+      assertArrayEquals(expectedValue, iterator.next());
+    }
+    expectThrows(NoSuchElementException.class, () -> iterator.next());
+    assertFalse(iterator.hasNext());
+  }
+
   public void testRangeOptimizesIfAllPointsMatch() throws IOException {
     final int numDims = TestUtil.nextInt(random(), 1, 3);
     Directory dir = newDirectory();