LUCENE-5683: remove inefficiencies in getXXXDocValues from SegmentReader

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1597055 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Robert Muir 2014-05-23 10:49:29 +00:00
parent d3bee7cb7f
commit 5810ff2d0e
2 changed files with 65 additions and 65 deletions

View File

@ -149,18 +149,23 @@ final class SegmentCoreReaders {
throw new AlreadyClosedException("SegmentCoreReaders is already closed");
}
NumericDocValues getNormValues(FieldInfo fi) throws IOException {
assert normsProducer != null;
NumericDocValues getNormValues(FieldInfos infos, String field) throws IOException {
Map<String,Object> normFields = normsLocal.get();
NumericDocValues norms = (NumericDocValues) normFields.get(fi.name);
if (norms == null) {
NumericDocValues norms = (NumericDocValues) normFields.get(field);
if (norms != null) {
return norms;
} else {
FieldInfo fi = infos.fieldInfo(field);
if (fi == null || !fi.hasNorms()) {
// Field does not exist or does not index norms
return null;
}
assert normsProducer != null;
norms = normsProducer.getNumeric(fi);
normFields.put(fi.name, norms);
normFields.put(field, norms);
return norms;
}
return norms;
}
void decRef() throws IOException {

View File

@ -445,48 +445,48 @@ public final class SegmentReader extends AtomicReader {
@Override
public NumericDocValues getNumericDocValues(String field) throws IOException {
ensureOpen();
FieldInfo fi = getDVField(field, DocValuesType.NUMERIC);
if (fi == null) {
return null;
}
Map<String,Object> dvFields = docValuesLocal.get();
NumericDocValues dvs = (NumericDocValues) dvFields.get(field);
if (dvs == null) {
Object previous = dvFields.get(field);
if (previous != null && previous instanceof NumericDocValues) {
return (NumericDocValues) previous;
} else {
FieldInfo fi = getDVField(field, DocValuesType.NUMERIC);
if (fi == null) {
return null;
}
DocValuesProducer dvProducer = dvProducersByField.get(field);
assert dvProducer != null;
dvs = dvProducer.getNumeric(fi);
dvFields.put(field, dvs);
NumericDocValues dv = dvProducer.getNumeric(fi);
dvFields.put(field, dv);
return dv;
}
return dvs;
}
@Override
public Bits getDocsWithField(String field) throws IOException {
ensureOpen();
FieldInfo fi = fieldInfos.fieldInfo(field);
if (fi == null) {
// Field does not exist
return null;
}
if (fi.getDocValuesType() == null) {
// Field was not indexed with doc values
return null;
}
Map<String,Bits> dvFields = docsWithFieldLocal.get();
Bits dvs = dvFields.get(field);
if (dvs == null) {
Bits previous = dvFields.get(field);
if (previous != null) {
return previous;
} else {
FieldInfo fi = fieldInfos.fieldInfo(field);
if (fi == null) {
// Field does not exist
return null;
}
if (fi.getDocValuesType() == null) {
// Field was not indexed with doc values
return null;
}
DocValuesProducer dvProducer = dvProducersByField.get(field);
assert dvProducer != null;
dvs = dvProducer.getDocsWithField(fi);
dvFields.put(field, dvs);
Bits dv = dvProducer.getDocsWithField(fi);
dvFields.put(field, dv);
return dv;
}
return dvs;
}
@Override
@ -513,54 +513,49 @@ public final class SegmentReader extends AtomicReader {
@Override
public SortedDocValues getSortedDocValues(String field) throws IOException {
ensureOpen();
FieldInfo fi = getDVField(field, DocValuesType.SORTED);
if (fi == null) {
return null;
}
Map<String,Object> dvFields = docValuesLocal.get();
SortedDocValues dvs = (SortedDocValues) dvFields.get(field);
if (dvs == null) {
Object previous = dvFields.get(field);
if (previous != null && previous instanceof SortedDocValues) {
return (SortedDocValues) previous;
} else {
FieldInfo fi = getDVField(field, DocValuesType.SORTED);
if (fi == null) {
return null;
}
DocValuesProducer dvProducer = dvProducersByField.get(field);
assert dvProducer != null;
dvs = dvProducer.getSorted(fi);
dvFields.put(field, dvs);
SortedDocValues dv = dvProducer.getSorted(fi);
dvFields.put(field, dv);
return dv;
}
return dvs;
}
@Override
public SortedSetDocValues getSortedSetDocValues(String field) throws IOException {
ensureOpen();
FieldInfo fi = getDVField(field, DocValuesType.SORTED_SET);
if (fi == null) {
return null;
}
Map<String,Object> dvFields = docValuesLocal.get();
SortedSetDocValues dvs = (SortedSetDocValues) dvFields.get(field);
if (dvs == null) {
Object previous = dvFields.get(field);
if (previous != null && previous instanceof SortedSetDocValues) {
return (SortedSetDocValues) previous;
} else {
FieldInfo fi = getDVField(field, DocValuesType.SORTED_SET);
if (fi == null) {
return null;
}
DocValuesProducer dvProducer = dvProducersByField.get(field);
assert dvProducer != null;
dvs = dvProducer.getSortedSet(fi);
dvFields.put(field, dvs);
SortedSetDocValues dv = dvProducer.getSortedSet(fi);
dvFields.put(field, dv);
return dv;
}
return dvs;
}
@Override
public NumericDocValues getNormValues(String field) throws IOException {
ensureOpen();
FieldInfo fi = fieldInfos.fieldInfo(field);
if (fi == null || !fi.hasNorms()) {
// Field does not exist or does not index norms
return null;
}
return core.getNormValues(fi);
return core.getNormValues(fieldInfos, field);
}
/**