Skip to content

Commit

Permalink
LUCENE-3647: for segments with no docvalues, when promoting to a fixe…
Browse files Browse the repository at this point in the history
…d type we need to use an EmptyFixedSource

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1214219 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
rmuir committed Dec 14, 2011
1 parent b2dbc82 commit 914ae9b
Showing 1 changed file with 67 additions and 1 deletion.
68 changes: 67 additions & 1 deletion lucene/src/java/org/apache/lucene/index/MultiDocValues.java
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,15 @@ protected void add(int base, IndexReader r) throws IOException {
DocValuesSlice slice = slices.get(i);
starts[i] = slice.start;
if (slice.docValues == null) {
slice.docValues = new EmptyDocValues(slice.length, promotedType[0].type());
Type promoted = promotedType[0].type();
switch(promoted) {
case BYTES_FIXED_DEREF:
case BYTES_FIXED_STRAIGHT:
slice.docValues = new EmptyFixedDocValues(slice.length, promoted, promotedType[0].getValueSize());
break;
default:
slice.docValues = new EmptyDocValues(slice.length, promoted);
}
}
}

Expand Down Expand Up @@ -147,6 +155,38 @@ public Source getDirectSource() throws IOException {
return emptySource;
}
}

public static class EmptyFixedDocValues extends DocValues {
final int maxDoc;
final Source emptyFixedSource;
final int valueSize;

public EmptyFixedDocValues(int maxDoc, Type type, int valueSize) {
this.maxDoc = maxDoc;
this.emptyFixedSource = new EmptyFixedSource(type, valueSize);
this.valueSize = valueSize;
}

@Override
public Source load() throws IOException {
return emptyFixedSource;
}

@Override
public Type type() {
return emptyFixedSource.type();
}

@Override
public int getValueSize() {
return valueSize;
}

@Override
public Source getDirectSource() throws IOException {
return emptyFixedSource;
}
}

private static class MultiSource extends Source {
private int numDocs = 0;
Expand Down Expand Up @@ -216,7 +256,33 @@ public EmptySource(Type type) {
public BytesRef getBytes(int docID, BytesRef ref) {
ref.length = 0;
return ref;
}

@Override
public double getFloat(int docID) {
return 0d;
}

@Override
public long getInt(int docID) {
return 0;
}
}

private static class EmptyFixedSource extends Source {
private final int valueSize;

public EmptyFixedSource(Type type, int valueSize) {
super(type);
this.valueSize = valueSize;
}

@Override
public BytesRef getBytes(int docID, BytesRef ref) {
ref.grow(valueSize);
ref.length = valueSize;
Arrays.fill(ref.bytes, ref.offset, ref.offset+valueSize, (byte)0);
return ref;
}

@Override
Expand Down

0 comments on commit 914ae9b

Please sign in to comment.