LUCENE-7890: The `SortedSetDocValues` and `SortedNumericDocValues` instances returned by the MemoryIndex should support subsequent `advanceExact(0)` invocations.

This commit is contained in:
Martijn van Groningen 2017-06-29 15:03:44 +02:00
parent c9c0121d93
commit 9f096200b2
No known key found for this signature in database
GPG Key ID: AB236F4FCF2AF12A
2 changed files with 44 additions and 2 deletions

View File

@ -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;
}

View File

@ -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));