From 138d8f12e8c90f0937259b037080b6f5debad111 Mon Sep 17 00:00:00 2001 From: Michael McCandless Date: Thu, 15 Nov 2012 18:01:39 +0000 Subject: [PATCH] add test case git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/branches/lucene4547@1409900 13f79535-47bb-0310-9956-ffa450edef68 --- .../SimpleTextSimpleDocValuesFormat.java | 3 +- .../org/apache/lucene/TestDemoDocValue.java | 32 +++++++++++++++++++ 2 files changed, 33 insertions(+), 2 deletions(-) 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.java index 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 { @Override public Source loadSource() throws IOException { - // nocommit todo DocValues.Type dvType = field.fieldInfo.getDocValuesType(); if (DocValues.isNumber(dvType)) { Source source = loadDirectSource(); @@ -576,7 +575,7 @@ public class SimpleTextSimpleDocValuesFormat extends SimpleDocValuesFormat { @Override public 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.java index 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(); + } + }