fix bug in default merge for numeric

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/branches/lucene4547@1410951 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Michael McCandless 2012-11-18 18:32:31 +00:00
parent d963fb1664
commit d9523ecdfc
3 changed files with 47 additions and 9 deletions

View File

@ -156,8 +156,14 @@ public class SimpleTextSimpleDocValuesFormat extends SimpleDocValuesFormat {
SimpleTextUtil.write(data, Long.toString(minValue), scratch);
SimpleTextUtil.writeNewline(data);
// build up our fixed-width "simple text packed ints" format
int maxBytesPerValue = BigInteger.valueOf(maxValue).subtract(BigInteger.valueOf(minValue)).toString().length();
assert maxValue >= minValue;
// build up our fixed-width "simple text packed ints"
// format
BigInteger maxBig = BigInteger.valueOf(maxValue);
BigInteger minBig = BigInteger.valueOf(minValue);
BigInteger diffBig = maxBig.subtract(minBig);
int maxBytesPerValue = diffBig.toString().length();
StringBuilder sb = new StringBuilder();
for (int i = 0; i < maxBytesPerValue; i++) {
sb.append('0');
@ -167,8 +173,10 @@ public class SimpleTextSimpleDocValuesFormat extends SimpleDocValuesFormat {
SimpleTextUtil.write(data, PATTERN);
SimpleTextUtil.write(data, sb.toString(), scratch);
SimpleTextUtil.writeNewline(data);
final String patternString = sb.toString();
final DecimalFormat encoder = new DecimalFormat(sb.toString(), new DecimalFormatSymbols(Locale.ROOT));
final DecimalFormat encoder = new DecimalFormat(patternString, new DecimalFormatSymbols(Locale.ROOT));
return new NumericDocValuesConsumer() {
int numDocsWritten = 0;
@ -176,7 +184,9 @@ public class SimpleTextSimpleDocValuesFormat extends SimpleDocValuesFormat {
public void add(long value) throws IOException {
assert value >= minValue;
Number delta = BigInteger.valueOf(value).subtract(BigInteger.valueOf(minValue));
SimpleTextUtil.write(data, encoder.format(delta), scratch);
String s = encoder.format(delta);
assert s.length() == patternString.length();
SimpleTextUtil.write(data, s, scratch);
SimpleTextUtil.writeNewline(data);
numDocsWritten++;
}

View File

@ -91,7 +91,7 @@ public abstract class SimpleDVConsumer implements Closeable {
if (liveDocs == null || liveDocs.get(i)) {
long val = docValues.get(i);
minValue = Math.min(val, minValue);
maxValue = Math.min(val, maxValue);
maxValue = Math.max(val, maxValue);
}
mergeState.checkAbort.work(300);
}

View File

@ -329,12 +329,12 @@ public class TestDemoDocValue extends LuceneTestCase {
IndexWriter iwriter = new IndexWriter(directory, iwc);
Document doc = new Document();
doc.add(newField("id", "0", StringField.TYPE_STORED));
doc.add(new PackedLongDocValuesField("dv", 1));
doc.add(new PackedLongDocValuesField("dv", -10));
iwriter.addDocument(doc);
iwriter.commit();
doc = new Document();
doc.add(newField("id", "1", StringField.TYPE_STORED));
doc.add(new PackedLongDocValuesField("dv", 3));
doc.add(new PackedLongDocValuesField("dv", 99));
iwriter.addDocument(doc);
iwriter.forceMerge(1);
iwriter.close();
@ -347,9 +347,9 @@ public class TestDemoDocValue extends LuceneTestCase {
StoredDocument doc2 = ireader.leaves().get(0).reader().document(i);
long expected;
if (doc2.get("id").equals("0")) {
expected = 1;
expected = -10;
} else {
expected = 3;
expected = 99;
}
assertEquals(expected, dv.get(i));
}
@ -386,6 +386,34 @@ public class TestDemoDocValue extends LuceneTestCase {
directory.close();
}
public void testRange2() throws IOException {
Analyzer analyzer = new MockAnalyzer(random());
Directory directory = newDirectory();
// 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 PackedLongDocValuesField("dv", -8841491950446638677L));
iwriter.addDocument(doc);
doc = new Document();
doc.add(new PackedLongDocValuesField("dv", 9062230939892376225L));
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;
NumericDocValues dv = ireader.leaves().get(0).reader().getNumericDocValues("dv");
assertEquals(-8841491950446638677L, dv.get(0));
assertEquals(9062230939892376225L, dv.get(1));
ireader.close();
directory.close();
}
public void testDemoBytes() throws IOException {
Analyzer analyzer = new MockAnalyzer(random());