get slow-wrapper working with dv2.0

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/branches/lucene4547@1432131 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Robert Muir 2013-01-11 16:17:19 +00:00
parent a38facf99a
commit f9bdb3cfd1
3 changed files with 96 additions and 47 deletions

View File

@ -604,46 +604,5 @@ class MultiDocValues extends DocValues {
@Override
protected Source loadDirectSource() throws IOException {
return new MultiSource(slices, starts, true, type);
}
public static NumericDocValues simpleNormValues(final IndexReader r, final String field) throws IOException {
final List<AtomicReaderContext> leaves = r.leaves();
if (leaves.size() == 1) {
return leaves.get(0).reader().simpleNormValues(field);
}
FieldInfo fi = MultiFields.getMergedFieldInfos(r).fieldInfo(field);
if (fi == null || fi.hasNorms() == false) {
return null;
}
boolean anyReal = false;
for(AtomicReaderContext ctx : leaves) {
NumericDocValues norms = ctx.reader().simpleNormValues(field);
if (norms != null) {
anyReal = true;
}
}
// assert anyReal; // nocommit: unsafe until 4.0 is done
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

@ -18,15 +18,58 @@ package org.apache.lucene.index;
*/
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import org.apache.lucene.codecs.Codec;
import org.apache.lucene.index.IndexReader.ReaderClosedListener;
import org.apache.lucene.store.Directory;
import org.apache.lucene.store.RAMDirectory;
import org.apache.lucene.util.Bits;
import org.apache.lucene.util.BytesRef;
import org.apache.lucene.util.IOUtils;
import org.apache.lucene.util.Version;
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 {
return MultiDocValues.simpleNormValues(r, field);
final List<AtomicReaderContext> leaves = r.leaves();
if (leaves.size() == 1) {
return leaves.get(0).reader().simpleNormValues(field);
}
FieldInfo fi = MultiFields.getMergedFieldInfos(r).fieldInfo(field);
if (fi == null || fi.hasNorms() == false) {
return null;
}
boolean anyReal = false;
for(AtomicReaderContext ctx : leaves) {
NumericDocValues norms = ctx.reader().simpleNormValues(field);
if (norms != null) {
anyReal = true;
}
}
// assert anyReal; // nocommit: unsafe until 4.0 is done
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);
}
}
};
}
public static NumericDocValues simpleNumericValues(final IndexReader r, final String field) throws IOException {
@ -105,4 +148,51 @@ public class MultiSimpleDocValues {
};
}
}
public static SortedDocValues simpleSortedValues(final IndexReader r, final String field) throws IOException {
final List<AtomicReaderContext> leaves = r.leaves();
if (leaves.size() == 1) {
return leaves.get(0).reader().getSortedDocValues(field);
}
boolean anyReal = false;
for(AtomicReaderContext ctx : leaves) {
SortedDocValues values = ctx.reader().getSortedDocValues(field);
if (values != null) {
anyReal = true;
}
}
if (!anyReal) {
return null;
} else {
// its called slow-wrapper for a reason right?
final Directory scratch = new RAMDirectory();
IndexWriterConfig config = new IndexWriterConfig(Version.LUCENE_50, null);
config.setCodec(Codec.forName("SimpleText"));
IndexWriter writer = new IndexWriter(scratch, config);
List<AtomicReader> newLeaves = new ArrayList<AtomicReader>();
for (AtomicReaderContext ctx : leaves) {
final AtomicReader a = ctx.reader();
newLeaves.add(new FilterAtomicReader(a) {
@Override
public Bits getLiveDocs() {
return null; // lie
}
});
}
writer.addIndexes(newLeaves.toArray(new AtomicReader[0]));
writer.close();
final IndexReader newR = DirectoryReader.open(scratch);
assert newR.leaves().size() == 1;
r.addReaderClosedListener(new ReaderClosedListener() {
@Override
public void onClose(IndexReader reader) {
IOUtils.closeWhileHandlingException(newR, scratch);
}
});
return newR.leaves().get(0).reader().getSortedDocValues(field);
}
}
}

View File

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