cleanups and fix for testduelingcodecs fail

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/branches/lucene4547@1432055 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Robert Muir 2013-01-11 13:59:59 +00:00
parent e646cf5f4f
commit 36076f67c6
7 changed files with 50 additions and 53 deletions

View File

@ -606,5 +606,43 @@ class MultiDocValues extends DocValues {
return new MultiSource(slices, starts, true, type);
}
public static NumericDocValues simpleNormValues(final IndexReader r, final String field) throws IOException {
FieldInfo fi = MultiFields.getMergedFieldInfos(r).fieldInfo(field);
if (fi == null || fi.hasNorms() == false) {
return null;
}
final List<AtomicReaderContext> leaves = r.leaves();
boolean anyReal = false;
for(AtomicReaderContext ctx : leaves) {
NumericDocValues norms = ctx.reader().simpleNormValues(field);
if (norms == null) {
norms = NumericDocValues.EMPTY;
} else {
anyReal = true;
}
}
assert anyReal; // nocommit: is this assert safe?
return new NumericDocValues() {
@Override
public long get(int docID) {
int subIndex = ReaderUtil.subIndex(docID, leaves);
NumericDocValues norms;
try {
norms = leaves.get(subIndex).reader().simpleNormValues(field);
} catch (IOException ioe) {
throw new RuntimeException(ioe);
}
if (norms == null) { // WTF? should be EMPTY?
return 0;
} else {
return norms.get(docID - leaves.get(subIndex).docBase);
}
}
};
}
}

View File

@ -61,15 +61,7 @@ final class NormsConsumerPerField extends InvertedDocEndConsumerPerField impleme
}
long norm = similarity.computeSimpleNorm(fieldState);
if (norm != -1) {
// nocommit is -1 really a safe "not set" value!?
// nocommit shouldn't we require that it's either
// all -1's or none? a sim can't not compute norms
// for only some docs? hmm unless the field is
// missing for this doc... but then finish() isn't
// called?
simpleNormsWriter.addValue(docState.docID, norm);
}
simpleNormsWriter.addValue(docState.docID, norm);
}
}

View File

@ -281,7 +281,7 @@ final class SegmentCoreReaders {
// Field does not exist
return null;
}
if (!fi.isIndexed() || fi.omitsNorms()) {
if (!fi.hasNorms()) {
return null;
}
// nocommit change to assert != null!!

View File

@ -228,7 +228,7 @@ final class SegmentMerger {
boolean success = false;
try {
for (FieldInfo field : mergeState.fieldInfos) {
if (field.isIndexed() && !field.omitsNorms() && field.getNormType() != null) {
if (field.hasNorms()) {
List<NumericDocValues> toMerge = new ArrayList<NumericDocValues>();
for (AtomicReader reader : mergeState.readers) {
NumericDocValues norms = reader.simpleNormValues(field.name);

View File

@ -91,19 +91,19 @@ public final class SlowCompositeReaderWrapper extends AtomicReader {
@Override
public NumericDocValues getNumericDocValues(String field) throws IOException {
ensureOpen();
return null;
return null; // nocommit: UOE
}
@Override
public BinaryDocValues getBinaryDocValues(String field) throws IOException {
ensureOpen();
return null;
return null; // nocommit: UOE
}
@Override
public SortedDocValues getSortedDocValues(String field) throws IOException {
ensureOpen();
return null;
return null; // nocommit: UOE
}
@Override
@ -121,7 +121,7 @@ public final class SlowCompositeReaderWrapper extends AtomicReader {
public NumericDocValues simpleNormValues(String field) throws IOException {
ensureOpen();
// nocommit hmm
return null;
return MultiDocValues.simpleNormValues(in, field);
}
@Override

View File

@ -537,10 +537,8 @@ public class TestDuelingCodecs extends LuceneTestCase {
if (leftNorms != null && rightNorms != null) {
assertDocValues(leftReader.maxDoc(), leftNorms, rightNorms);
} else {
// nocommit: figure out WTF is going on here, maybe a bug in MultiSimpleDocValues?
// ant test -Dtestcase=TestDuelingCodecs -Dtests.method=testEquals -Dtests.seed=CCA808E6ADF64354 -Dtests.slow=true -Dtests.codec=Lucene41 -Dtests.locale=en_GB -Dtests.timezone=Asia/Pyongyang -Dtests.file.encoding=US-ASCII
assertNull(leftNorms);
assertNull(rightNorms);
assertNull(info, leftNorms);
assertNull(info, rightNorms);
}
}
}

View File

@ -23,41 +23,10 @@ import java.util.List;
import org.apache.lucene.util.BytesRef;
public class MultiSimpleDocValues {
// moved to src/java so SlowWrapper can use it... uggggggh
public static NumericDocValues simpleNormValues(final IndexReader r, final String field) throws IOException {
final List<AtomicReaderContext> leaves = r.leaves();
boolean anyReal = false;
for(AtomicReaderContext ctx : leaves) {
NumericDocValues norms = ctx.reader().simpleNormValues(field);
if (norms == null) {
norms = NumericDocValues.EMPTY;
} else {
anyReal = true;
}
}
if (!anyReal) {
return null;
} else {
return new NumericDocValues() {
@Override
public long get(int docID) {
int subIndex = ReaderUtil.subIndex(docID, leaves);
NumericDocValues norms;
try {
norms = leaves.get(subIndex).reader().simpleNormValues(field);
} catch (IOException ioe) {
throw new RuntimeException(ioe);
}
if (norms == null) {
return 0;
} else {
return norms.get(docID - leaves.get(subIndex).docBase);
}
}
};
}
return MultiDocValues.simpleNormValues(r, field);
}
public static NumericDocValues simpleNumericValues(final IndexReader r, final String field) throws IOException {