fix simpletext nocommits

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/branches/lucene4547@1436647 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Robert Muir 2013-01-21 22:04:18 +00:00
parent 041a0f424f
commit 456e12fbd8
3 changed files with 18 additions and 18 deletions

View File

@ -34,6 +34,7 @@ import org.apache.lucene.index.SegmentWriteState;
* for numbers this is a "fixed-width" file, for example a single byte range:
* <pre>
* field myField
* type NUMERIC
* minvalue 0
* pattern 000
* 005
@ -47,6 +48,7 @@ import org.apache.lucene.index.SegmentWriteState;
* for bytes this is also a "fixed-width" file, for example:
* <pre>
* field myField
* type BINARY
* maxlength 6
* pattern 0
* length 6
@ -61,6 +63,7 @@ import org.apache.lucene.index.SegmentWriteState;
* for sorted bytes this is a fixed-width file, for example:
* <pre>
* field myField
* type SORTED
* numvalues 10
* maxLength 8
* pattern 0

View File

@ -48,7 +48,7 @@ import static org.apache.lucene.codecs.simpletext.SimpleTextDocValuesWriter.MINV
import static org.apache.lucene.codecs.simpletext.SimpleTextDocValuesWriter.NUMVALUES;
import static org.apache.lucene.codecs.simpletext.SimpleTextDocValuesWriter.ORDPATTERN;
import static org.apache.lucene.codecs.simpletext.SimpleTextDocValuesWriter.PATTERN;
import static org.apache.lucene.codecs.simpletext.SimpleTextDocValuesWriter.TYPE;
// nocommit make sure we test "all docs have 0 value",
// "all docs have empty BytesREf"
@ -56,7 +56,6 @@ import static org.apache.lucene.codecs.simpletext.SimpleTextDocValuesWriter.PATT
class SimpleTextDocValuesReader extends DocValuesProducer {
static class OneField {
FieldInfo fieldInfo;
long dataStartFilePointer;
String pattern;
String ordPattern;
@ -90,11 +89,10 @@ class SimpleTextDocValuesReader extends DocValuesProducer {
OneField field = new OneField();
fields.put(fieldName, field);
field.fieldInfo = fieldInfo;
//System.out.println(" field=" + fieldName);
readLine();
assert startsWith(TYPE) : scratch.utf8ToString();
// nocommit hack hack hack!!:
DocValuesType dvType = ext.equals("len") ? DocValuesType.NUMERIC : fieldInfo.getDocValuesType();
DocValuesType dvType = DocValuesType.valueOf(stripPrefix(TYPE));
assert dvType != null;
if (dvType == DocValuesType.NUMERIC) {
readLine();

View File

@ -37,6 +37,7 @@ import org.apache.lucene.util.IOUtils;
class SimpleTextDocValuesWriter extends DocValuesConsumer {
final static BytesRef END = new BytesRef("END");
final static BytesRef FIELD = new BytesRef("field ");
final static BytesRef TYPE = new BytesRef(" type ");
// used for numerics
final static BytesRef MINVALUE = new BytesRef(" minvalue ");
final static BytesRef PATTERN = new BytesRef(" pattern ");
@ -50,15 +51,12 @@ class SimpleTextDocValuesWriter extends DocValuesConsumer {
final IndexOutput data;
final BytesRef scratch = new BytesRef();
final int numDocs;
// nocommit
final boolean isNorms;
private final Set<String> fieldsSeen = new HashSet<String>(); // for asserting
public SimpleTextDocValuesWriter(SegmentWriteState state, String ext) throws IOException {
//System.out.println("WRITE: " + IndexFileNames.segmentFileName(state.segmentInfo.name, state.segmentSuffix, ext) + " " + state.segmentInfo.getDocCount() + " docs");
data = state.directory.createOutput(IndexFileNames.segmentFileName(state.segmentInfo.name, state.segmentSuffix, ext), state.context);
numDocs = state.segmentInfo.getDocCount();
isNorms = ext.equals("len");
}
// for asserting
@ -71,10 +69,9 @@ class SimpleTextDocValuesWriter extends DocValuesConsumer {
@Override
public void addNumericField(FieldInfo field, Iterable<Number> values) throws IOException {
assert fieldSeen(field.name);
// nocommit: this must be multiple asserts
//assert (field.getDocValuesType() != null && (DocValues.isNumber(field.getDocValuesType()) || DocValues.isFloat(field.getDocValuesType()))) ||
// (field.getNormType() != null && (DocValues.isNumber(field.getNormType()) || DocValues.isFloat(field.getNormType()))): "field=" + field.name;
writeFieldEntry(field);
assert (field.getDocValuesType() == FieldInfo.DocValuesType.NUMERIC ||
field.getNormType() == FieldInfo.DocValuesType.NUMERIC);
writeFieldEntry(field, FieldInfo.DocValuesType.NUMERIC);
// first pass to find min/max
long minValue = Long.MAX_VALUE;
@ -132,12 +129,11 @@ class SimpleTextDocValuesWriter extends DocValuesConsumer {
public void addBinaryField(FieldInfo field, Iterable<BytesRef> values) throws IOException {
assert fieldSeen(field.name);
assert field.getDocValuesType() == DocValuesType.BINARY;
assert !isNorms;
int maxLength = 0;
for(BytesRef value : values) {
maxLength = Math.max(maxLength, value.length);
}
writeFieldEntry(field);
writeFieldEntry(field, FieldInfo.DocValuesType.BINARY);
// write maxLength
SimpleTextUtil.write(data, MAXLENGTH);
@ -181,8 +177,7 @@ class SimpleTextDocValuesWriter extends DocValuesConsumer {
public void addSortedField(FieldInfo field, Iterable<BytesRef> values, Iterable<Number> docToOrd) throws IOException {
assert fieldSeen(field.name);
assert field.getDocValuesType() == DocValuesType.SORTED;
assert !isNorms;
writeFieldEntry(field);
writeFieldEntry(field, FieldInfo.DocValuesType.SORTED);
int valueCount = 0;
int maxLength = -1;
@ -256,10 +251,14 @@ class SimpleTextDocValuesWriter extends DocValuesConsumer {
}
/** write the header for this field */
private void writeFieldEntry(FieldInfo field) throws IOException {
private void writeFieldEntry(FieldInfo field, FieldInfo.DocValuesType type) throws IOException {
SimpleTextUtil.write(data, FIELD);
SimpleTextUtil.write(data, field.name, scratch);
SimpleTextUtil.writeNewline(data);
SimpleTextUtil.write(data, TYPE);
SimpleTextUtil.write(data, type.toString(), scratch);
SimpleTextUtil.writeNewline(data);
}
@Override