don't load MultiDocValues for norms if one leaf reader omits norms

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1230482 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Simon Willnauer 2012-01-12 10:53:53 +00:00
parent d74db06ddf
commit 8913c0c597
1 changed files with 17 additions and 0 deletions

View File

@ -46,6 +46,12 @@ public class MultiDocValues extends DocValues {
public DocValues pull(IndexReader reader, String field) throws IOException {
return reader.normValues(field);
}
public boolean stopLoadingOnNull(IndexReader reader, String field) throws IOException {
// for norms we drop all norms if one leaf reader has no norms and the field is present
Fields fields = reader.fields();
return (fields != null && fields.terms(field) != null);
}
};
public static class DocValuesSlice {
@ -65,6 +71,10 @@ public class MultiDocValues extends DocValues {
public DocValues pull(IndexReader reader, String field) throws IOException {
return reader.docValues(field);
}
public boolean stopLoadingOnNull(IndexReader reader, String field) throws IOException {
return false;
}
}
private DocValuesSlice[] slices;
@ -123,12 +133,19 @@ public class MultiDocValues extends DocValues {
// potentially incompatible types
new ReaderUtil.Gather(r) {
boolean stop = false;
@Override
protected void add(int base, IndexReader r) throws IOException {
if (stop) {
return;
}
final DocValues d = puller.pull(r, field);
if (d != null) {
TypePromoter incoming = TypePromoter.create(d.type(), d.getValueSize());
promotedType[0] = promotedType[0].promote(incoming);
} else if (puller.stopLoadingOnNull(r, field)){
promotedType[0] = TypePromoter.getIdentityPromoter(); // set to identity to return null
stop = true;
}
slices.add(new DocValuesSlice(d, base, r.maxDoc()));
}