lucene-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From m..@apache.org
Subject [1/2] lucene-solr:master: LUCENE-7307: Add getters to the PointInSetQuery and PointRangeQuery queries.
Date Thu, 02 Jun 2016 13:07:54 GMT
Repository: lucene-solr
Updated Branches:
  refs/heads/branch_6x 734dcb99f -> 50feae82a
  refs/heads/master 9863d3d2d -> b97727518


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/b9772751
Tree: http://git-wip-us.apache.org/repos/asf/lucene-solr/tree/b9772751
Diff: http://git-wip-us.apache.org/repos/asf/lucene-solr/diff/b9772751

Branch: refs/heads/master
Commit: b977275185a111fad55da2bd993c1afb73a00b51
Parents: 9863d3d
Author: Martijn van Groningen <mvg@apache.org>
Authored: Wed Jun 1 11:42:00 2016 +0200
Committer: Martijn van Groningen <mvg@apache.org>
Committed: Thu Jun 2 14:33:29 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/b9772751/lucene/CHANGES.txt
----------------------------------------------------------------------
diff --git a/lucene/CHANGES.txt b/lucene/CHANGES.txt
index 96f5ae9..486f8b3 100644
--- a/lucene/CHANGES.txt
+++ b/lucene/CHANGES.txt
@@ -172,6 +172,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/b9772751/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/b9772751/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/b9772751/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 078c8da..cf8372d 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();


Mime
View raw message