mirror of https://github.com/apache/lucene.git
add readers for 4.0 numeric types
git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/branches/lucene4547@1437619 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
68b84368c6
commit
c03b74d1bd
|
@ -54,4 +54,14 @@ public class Lucene40DocValuesFormat extends DocValuesFormat {
|
|||
|
||||
static final byte VAR_INTS_PACKED = 0x00;
|
||||
static final byte VAR_INTS_FIXED_64 = 0x01;
|
||||
|
||||
// constants for FIXED_INTS_8, FIXED_INTS_16, FIXED_INTS_32, FIXED_INTS_64
|
||||
static final String INTS_CODEC_NAME = "Ints";
|
||||
static final int INTS_VERSION_START = 0;
|
||||
static final int INTS_VERSION_CURRENT = INTS_VERSION_START;
|
||||
|
||||
// constants for FLOAT_32, FLOAT_64
|
||||
static final String FLOATS_CODEC_NAME = "Floats";
|
||||
static final int FLOATS_VERSION_START = 0;
|
||||
static final int FLOATS_VERSION_CURRENT = FLOATS_VERSION_START;
|
||||
}
|
||||
|
|
|
@ -64,6 +64,24 @@ class Lucene40DocValuesReader extends DocValuesProducer {
|
|||
case VAR_INTS:
|
||||
instance = loadVarIntsField(field);
|
||||
break;
|
||||
case FIXED_INTS_8:
|
||||
instance = loadByteField(field);
|
||||
break;
|
||||
case FIXED_INTS_16:
|
||||
instance = loadShortField(field);
|
||||
break;
|
||||
case FIXED_INTS_32:
|
||||
instance = loadIntField(field);
|
||||
break;
|
||||
case FIXED_INTS_64:
|
||||
instance = loadLongField(field);
|
||||
break;
|
||||
case FLOAT_32:
|
||||
instance = loadFloatField(field);
|
||||
break;
|
||||
case FLOAT_64:
|
||||
instance = loadDoubleField(field);
|
||||
break;
|
||||
default:
|
||||
throw new AssertionError(); // nocommit, implement the other types
|
||||
}
|
||||
|
@ -120,6 +138,178 @@ class Lucene40DocValuesReader extends DocValuesProducer {
|
|||
}
|
||||
}
|
||||
|
||||
private NumericDocValues loadByteField(FieldInfo field) throws IOException {
|
||||
String fileName = IndexFileNames.segmentFileName(state.segmentInfo.name, Integer.toString(field.number), "dat");
|
||||
IndexInput input = dir.openInput(fileName, state.context);
|
||||
boolean success = false;
|
||||
try {
|
||||
CodecUtil.checkHeader(input, Lucene40DocValuesFormat.INTS_CODEC_NAME,
|
||||
Lucene40DocValuesFormat.INTS_VERSION_START,
|
||||
Lucene40DocValuesFormat.INTS_VERSION_CURRENT);
|
||||
input.readInt();
|
||||
int maxDoc = state.segmentInfo.getDocCount();
|
||||
final byte values[] = new byte[maxDoc];
|
||||
input.readBytes(values, 0, values.length);
|
||||
return new NumericDocValues() {
|
||||
@Override
|
||||
public long get(int docID) {
|
||||
return values[docID];
|
||||
}
|
||||
};
|
||||
} finally {
|
||||
if (success) {
|
||||
IOUtils.close(input);
|
||||
} else {
|
||||
IOUtils.closeWhileHandlingException(input);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private NumericDocValues loadShortField(FieldInfo field) throws IOException {
|
||||
String fileName = IndexFileNames.segmentFileName(state.segmentInfo.name, Integer.toString(field.number), "dat");
|
||||
IndexInput input = dir.openInput(fileName, state.context);
|
||||
boolean success = false;
|
||||
try {
|
||||
CodecUtil.checkHeader(input, Lucene40DocValuesFormat.INTS_CODEC_NAME,
|
||||
Lucene40DocValuesFormat.INTS_VERSION_START,
|
||||
Lucene40DocValuesFormat.INTS_VERSION_CURRENT);
|
||||
input.readInt();
|
||||
int maxDoc = state.segmentInfo.getDocCount();
|
||||
final short values[] = new short[maxDoc];
|
||||
for (int i = 0; i < values.length; i++) {
|
||||
values[i] = input.readShort();
|
||||
}
|
||||
return new NumericDocValues() {
|
||||
@Override
|
||||
public long get(int docID) {
|
||||
return values[docID];
|
||||
}
|
||||
};
|
||||
} finally {
|
||||
if (success) {
|
||||
IOUtils.close(input);
|
||||
} else {
|
||||
IOUtils.closeWhileHandlingException(input);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private NumericDocValues loadIntField(FieldInfo field) throws IOException {
|
||||
String fileName = IndexFileNames.segmentFileName(state.segmentInfo.name, Integer.toString(field.number), "dat");
|
||||
IndexInput input = dir.openInput(fileName, state.context);
|
||||
boolean success = false;
|
||||
try {
|
||||
CodecUtil.checkHeader(input, Lucene40DocValuesFormat.INTS_CODEC_NAME,
|
||||
Lucene40DocValuesFormat.INTS_VERSION_START,
|
||||
Lucene40DocValuesFormat.INTS_VERSION_CURRENT);
|
||||
input.readInt();
|
||||
int maxDoc = state.segmentInfo.getDocCount();
|
||||
final int values[] = new int[maxDoc];
|
||||
for (int i = 0; i < values.length; i++) {
|
||||
values[i] = input.readInt();
|
||||
}
|
||||
return new NumericDocValues() {
|
||||
@Override
|
||||
public long get(int docID) {
|
||||
return values[docID];
|
||||
}
|
||||
};
|
||||
} finally {
|
||||
if (success) {
|
||||
IOUtils.close(input);
|
||||
} else {
|
||||
IOUtils.closeWhileHandlingException(input);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private NumericDocValues loadLongField(FieldInfo field) throws IOException {
|
||||
String fileName = IndexFileNames.segmentFileName(state.segmentInfo.name, Integer.toString(field.number), "dat");
|
||||
IndexInput input = dir.openInput(fileName, state.context);
|
||||
boolean success = false;
|
||||
try {
|
||||
CodecUtil.checkHeader(input, Lucene40DocValuesFormat.INTS_CODEC_NAME,
|
||||
Lucene40DocValuesFormat.INTS_VERSION_START,
|
||||
Lucene40DocValuesFormat.INTS_VERSION_CURRENT);
|
||||
input.readInt();
|
||||
int maxDoc = state.segmentInfo.getDocCount();
|
||||
final long values[] = new long[maxDoc];
|
||||
for (int i = 0; i < values.length; i++) {
|
||||
values[i] = input.readLong();
|
||||
}
|
||||
return new NumericDocValues() {
|
||||
@Override
|
||||
public long get(int docID) {
|
||||
return values[docID];
|
||||
}
|
||||
};
|
||||
} finally {
|
||||
if (success) {
|
||||
IOUtils.close(input);
|
||||
} else {
|
||||
IOUtils.closeWhileHandlingException(input);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private NumericDocValues loadFloatField(FieldInfo field) throws IOException {
|
||||
String fileName = IndexFileNames.segmentFileName(state.segmentInfo.name, Integer.toString(field.number), "dat");
|
||||
IndexInput input = dir.openInput(fileName, state.context);
|
||||
boolean success = false;
|
||||
try {
|
||||
CodecUtil.checkHeader(input, Lucene40DocValuesFormat.FLOATS_CODEC_NAME,
|
||||
Lucene40DocValuesFormat.FLOATS_VERSION_START,
|
||||
Lucene40DocValuesFormat.FLOATS_VERSION_CURRENT);
|
||||
input.readInt();
|
||||
int maxDoc = state.segmentInfo.getDocCount();
|
||||
final int values[] = new int[maxDoc];
|
||||
for (int i = 0; i < values.length; i++) {
|
||||
values[i] = input.readInt();
|
||||
}
|
||||
return new NumericDocValues() {
|
||||
@Override
|
||||
public long get(int docID) {
|
||||
return values[docID];
|
||||
}
|
||||
};
|
||||
} finally {
|
||||
if (success) {
|
||||
IOUtils.close(input);
|
||||
} else {
|
||||
IOUtils.closeWhileHandlingException(input);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private NumericDocValues loadDoubleField(FieldInfo field) throws IOException {
|
||||
String fileName = IndexFileNames.segmentFileName(state.segmentInfo.name, Integer.toString(field.number), "dat");
|
||||
IndexInput input = dir.openInput(fileName, state.context);
|
||||
boolean success = false;
|
||||
try {
|
||||
CodecUtil.checkHeader(input, Lucene40DocValuesFormat.FLOATS_CODEC_NAME,
|
||||
Lucene40DocValuesFormat.FLOATS_VERSION_START,
|
||||
Lucene40DocValuesFormat.FLOATS_VERSION_CURRENT);
|
||||
input.readInt();
|
||||
int maxDoc = state.segmentInfo.getDocCount();
|
||||
final long values[] = new long[maxDoc];
|
||||
for (int i = 0; i < values.length; i++) {
|
||||
values[i] = input.readLong();
|
||||
}
|
||||
return new NumericDocValues() {
|
||||
@Override
|
||||
public long get(int docID) {
|
||||
return values[docID];
|
||||
}
|
||||
};
|
||||
} finally {
|
||||
if (success) {
|
||||
IOUtils.close(input);
|
||||
} else {
|
||||
IOUtils.closeWhileHandlingException(input);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized BinaryDocValues getBinary(FieldInfo field) throws IOException {
|
||||
throw new AssertionError();
|
||||
|
|
Loading…
Reference in New Issue