lucene-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sha...@apache.org
Subject [20/53] [abbrv] lucene-solr:feature/autoscaling: LUCENE-7890: The `SortedSetDocValues` and `SortedNumericDocValues` instances returned by the MemoryIndex should support subsequent `advanceExact(0)` invocations.
Date Tue, 04 Jul 2017 01:23:40 GMT
LUCENE-7890: The `SortedSetDocValues` and `SortedNumericDocValues` instances returned by the
MemoryIndex should support subsequent `advanceExact(0)` invocations.


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

Branch: refs/heads/feature/autoscaling
Commit: 9f096200b23ca1ff7b9d3c864c27a5b2b707f62a
Parents: c9c0121
Author: Martijn van Groningen <mvg@apache.org>
Authored: Thu Jun 29 15:03:44 2017 +0200
Committer: Martijn van Groningen <mvg@apache.org>
Committed: Thu Jun 29 15:03:44 2017 +0200

----------------------------------------------------------------------
 .../apache/lucene/index/memory/MemoryIndex.java |  6 ++-
 .../lucene/index/memory/TestMemoryIndex.java    | 40 ++++++++++++++++++++
 2 files changed, 44 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/9f096200/lucene/memory/src/java/org/apache/lucene/index/memory/MemoryIndex.java
----------------------------------------------------------------------
diff --git a/lucene/memory/src/java/org/apache/lucene/index/memory/MemoryIndex.java b/lucene/memory/src/java/org/apache/lucene/index/memory/MemoryIndex.java
index 9812a39..fa6b564 100644
--- a/lucene/memory/src/java/org/apache/lucene/index/memory/MemoryIndex.java
+++ b/lucene/memory/src/java/org/apache/lucene/index/memory/MemoryIndex.java
@@ -938,11 +938,11 @@ public class MemoryIndex {
     MemoryDocValuesIterator it = new MemoryDocValuesIterator();
     return new SortedNumericDocValues() {
 
-      int value = 0;
+      int ord = 0;
 
       @Override
       public long nextValue() throws IOException {
-        return values[value++];
+        return values[ord++];
       }
 
       @Override
@@ -952,6 +952,7 @@ public class MemoryIndex {
 
       @Override
       public boolean advanceExact(int target) throws IOException {
+        ord = 0;
         return it.advance(target) == target;
       }
 
@@ -1082,6 +1083,7 @@ public class MemoryIndex {
 
       @Override
       public boolean advanceExact(int target) throws IOException {
+        ord = 0;
         return it.advance(target) == target;
       }
 

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/9f096200/lucene/memory/src/test/org/apache/lucene/index/memory/TestMemoryIndex.java
----------------------------------------------------------------------
diff --git a/lucene/memory/src/test/org/apache/lucene/index/memory/TestMemoryIndex.java b/lucene/memory/src/test/org/apache/lucene/index/memory/TestMemoryIndex.java
index d4ce8f1..a737aad 100644
--- a/lucene/memory/src/test/org/apache/lucene/index/memory/TestMemoryIndex.java
+++ b/lucene/memory/src/test/org/apache/lucene/index/memory/TestMemoryIndex.java
@@ -302,6 +302,46 @@ public class TestMemoryIndex extends LuceneTestCase {
     assertEquals("f", sortedSetDocValues.lookupOrd(2L).utf8ToString());
   }
 
+  public void testDocValues_resetIterator() throws Exception {
+    Document doc = new Document();
+
+    doc.add(new SortedSetDocValuesField("sorted_set", new BytesRef("f")));
+    doc.add(new SortedSetDocValuesField("sorted_set", new BytesRef("d")));
+    doc.add(new SortedSetDocValuesField("sorted_set", new BytesRef("d")));
+    doc.add(new SortedSetDocValuesField("sorted_set", new BytesRef("c")));
+
+    doc.add(new SortedNumericDocValuesField("sorted_numeric", 33L));
+    doc.add(new SortedNumericDocValuesField("sorted_numeric", 32L));
+    doc.add(new SortedNumericDocValuesField("sorted_numeric", 32L));
+    doc.add(new SortedNumericDocValuesField("sorted_numeric", 31L));
+    doc.add(new SortedNumericDocValuesField("sorted_numeric", 30L));
+
+    MemoryIndex mi = MemoryIndex.fromDocument(doc, analyzer);
+    LeafReader leafReader = mi.createSearcher().getIndexReader().leaves().get(0).reader();
+
+    SortedSetDocValues sortedSetDocValues = leafReader.getSortedSetDocValues("sorted_set");
+    assertEquals(3, sortedSetDocValues.getValueCount());
+    for (int times = 0; times < 3; times++) {
+      assertTrue(sortedSetDocValues.advanceExact(0));
+      assertEquals(0L, sortedSetDocValues.nextOrd());
+      assertEquals(1L, sortedSetDocValues.nextOrd());
+      assertEquals(2L, sortedSetDocValues.nextOrd());
+      assertEquals(SortedSetDocValues.NO_MORE_ORDS, sortedSetDocValues.nextOrd());
+    }
+
+    SortedNumericDocValues sortedNumericDocValues = leafReader.getSortedNumericDocValues("sorted_numeric");
+    for (int times = 0; times < 3; times++) {
+      assertTrue(sortedNumericDocValues.advanceExact(0));
+      assertEquals(5, sortedNumericDocValues.docValueCount());
+      assertEquals(30L, sortedNumericDocValues.nextValue());
+      assertEquals(31L, sortedNumericDocValues.nextValue());
+      assertEquals(32L, sortedNumericDocValues.nextValue());
+      assertEquals(32L, sortedNumericDocValues.nextValue());
+      assertEquals(33L, sortedNumericDocValues.nextValue());
+    }
+
+  }
+
   public void testInvalidDocValuesUsage() throws Exception {
     Document doc = new Document();
     doc.add(new NumericDocValuesField("field", 29L));


Mime
View raw message