Apache Lucene open-source search software
add test case
Michael McCandless138d8f12e8c9
diff --git a/lucene/codecs/src/java/org/apache/lucene/codecs/simpletext/SimpleTextSimpleDocValuesFormat.java b/lucene/codecs/src/java/org/apache/lucene/codecs/simpletext/SimpleTextSimpleDocValuesFormat.javaindex 890173f47ac..02e2a854685 100644--- a/lucene/codecs/src/java/org/apache/lucene/codecs/simpletext/SimpleTextSimpleDocValuesFormat.java+++ b/lucene/codecs/src/java/org/apache/lucene/codecs/simpletext/SimpleTextSimpleDocValuesFormat.java@@ -421,7 +421,6 @@ public class SimpleTextSimpleDocValuesFormat extends SimpleDocValuesFormat {@Overridepublic Source loadSource() throws IOException {- // nocommit todoDocValues.Type dvType = field.fieldInfo.getDocValuesType();if (DocValues.isNumber(dvType)) {Source source = loadDirectSource();@@ -576,7 +575,7 @@ public class SimpleTextSimpleDocValuesFormat extends SimpleDocValuesFormat {@Overridepublic int ord(int docID) {try {- in.seek(field.dataStartFilePointer + field.numValues * (9 + field.pattern.length() + field.maxLength) + (1 + field.ordPattern.length()) * docID);+ in.seek(field.dataStartFilePointer + field.numValues * (9 + field.pattern.length() + field.maxLength) + docID * (1 + field.ordPattern.length()));SimpleTextUtil.readLine(in, scratch);try {return ordDecoder.parse(scratch.utf8ToString()).intValue();diff --git a/lucene/core/src/test/org/apache/lucene/TestDemoDocValue.java b/lucene/core/src/test/org/apache/lucene/TestDemoDocValue.javaindex 3df68d0bb59..96c564ad504 100644--- a/lucene/core/src/test/org/apache/lucene/TestDemoDocValue.java+++ b/lucene/core/src/test/org/apache/lucene/TestDemoDocValue.java@@ -241,4 +241,36 @@ public class TestDemoDocValue extends LuceneTestCase {ireader.close();directory.close();}++ public void testSortedBytesTwoDocuments() throws IOException {+ Analyzer analyzer = new MockAnalyzer(random());++ // Store the index in memory:+ Directory directory = newDirectory();+ // To store an index on disk, use this instead:+ // Directory directory = FSDirectory.open(new File("/tmp/testindex"));+ // we don't use RandomIndexWriter because it might add more docvalues than we expect !!!!1+ IndexWriterConfig iwc = newIndexWriterConfig(TEST_VERSION_CURRENT, analyzer);+ iwc.setMergePolicy(newLogMergePolicy());+ IndexWriter iwriter = new IndexWriter(directory, iwc);+ Document doc = new Document();+ doc.add(new SortedBytesDocValuesField("dv", new BytesRef("hello world 1")));+ iwriter.addDocument(doc);+ doc = new Document();+ doc.add(new SortedBytesDocValuesField("dv", new BytesRef("hello world 2")));+ iwriter.addDocument(doc);+ iwriter.forceMerge(1);+ iwriter.close();++ // Now search the index:+ IndexReader ireader = DirectoryReader.open(directory); // read-only=true+ assert ireader.leaves().size() == 1;+ DocValues dv = ireader.leaves().get(0).reader().docValues("dv");+ assertEquals("hello world 1", dv.getSource().getBytes(0, new BytesRef()).utf8ToString());+ assertEquals("hello world 2", dv.getSource().getBytes(1, new BytesRef()).utf8ToString());++ ireader.close();+ directory.close();+ }+}