mirror of https://github.com/apache/lucene.git
fix simpletext to encode with biginteger
git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/branches/lucene4547@1409653 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
3e82da5bc7
commit
b1fb696dca
|
@ -17,6 +17,8 @@ package org.apache.lucene.codecs.simpletext;
|
|||
* limitations under the License.
|
||||
*/
|
||||
import java.io.IOException;
|
||||
import java.math.BigDecimal;
|
||||
import java.math.BigInteger;
|
||||
import java.text.DecimalFormat;
|
||||
import java.text.DecimalFormatSymbols;
|
||||
import java.text.ParseException;
|
||||
|
@ -149,7 +151,7 @@ public class SimpleTextSimpleDocValuesFormat extends SimpleDocValuesFormat {
|
|||
SimpleTextUtil.writeNewline(data);
|
||||
|
||||
// build up our fixed-width "simple text packed ints" format
|
||||
int maxBytesPerValue = Long.toString(maxValue - minValue).length();
|
||||
int maxBytesPerValue = BigInteger.valueOf(maxValue).subtract(BigInteger.valueOf(minValue)).toString().length();
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (int i = 0; i < maxBytesPerValue; i++) {
|
||||
sb.append('0');
|
||||
|
@ -166,7 +168,7 @@ public class SimpleTextSimpleDocValuesFormat extends SimpleDocValuesFormat {
|
|||
|
||||
@Override
|
||||
public void add(long value) throws IOException {
|
||||
long delta = value - minValue;
|
||||
Number delta = BigInteger.valueOf(value).subtract(BigInteger.valueOf(minValue));
|
||||
SimpleTextUtil.write(data, encoder.format(delta), scratch);
|
||||
SimpleTextUtil.writeNewline(data);
|
||||
numDocsWritten++;
|
||||
|
@ -510,6 +512,7 @@ public class SimpleTextSimpleDocValuesFormat extends SimpleDocValuesFormat {
|
|||
final DecimalFormat decoder = new DecimalFormat(field.pattern, new DecimalFormatSymbols(Locale.ROOT));
|
||||
|
||||
if (DocValues.isNumber(dvType)) {
|
||||
decoder.setParseBigDecimal(true);
|
||||
return new Source(dvType) {
|
||||
@Override
|
||||
public long getInt(int docID) {
|
||||
|
@ -520,7 +523,8 @@ public class SimpleTextSimpleDocValuesFormat extends SimpleDocValuesFormat {
|
|||
in.seek(field.dataStartFilePointer + (1+field.pattern.length())*docID);
|
||||
SimpleTextUtil.readLine(in, scratch);
|
||||
System.out.println("parsing delta: " + scratch.utf8ToString());
|
||||
return field.minValue + decoder.parse(scratch.utf8ToString(), new ParsePosition(0)).longValue();
|
||||
BigDecimal bd = (BigDecimal) decoder.parse(scratch.utf8ToString(), new ParsePosition(0));
|
||||
return BigInteger.valueOf(field.minValue).add(bd.toBigIntegerExact()).longValue();
|
||||
} catch (IOException ioe) {
|
||||
throw new RuntimeException(ioe);
|
||||
}
|
||||
|
|
|
@ -122,7 +122,6 @@ public class TestDemoDocValue extends LuceneTestCase {
|
|||
directory.close();
|
||||
}
|
||||
|
||||
@Ignore("get ST to use bigdecimal, also negatives are maybe not working yet!")
|
||||
public void testBigRange() throws IOException {
|
||||
Analyzer analyzer = new MockAnalyzer(random());
|
||||
|
||||
|
|
Loading…
Reference in New Issue