From 5810ff2d0e611b1da5c83e0600b3f59181778853 Mon Sep 17 00:00:00 2001 From: Robert Muir Date: Fri, 23 May 2014 10:49:29 +0000 Subject: [PATCH] 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 --- .../lucene/index/SegmentCoreReaders.java | 21 ++-- .../apache/lucene/index/SegmentReader.java | 109 +++++++++--------- 2 files changed, 65 insertions(+), 65 deletions(-) diff --git a/lucene/core/src/java/org/apache/lucene/index/SegmentCoreReaders.java b/lucene/core/src/java/org/apache/lucene/index/SegmentCoreReaders.java index f0a584cb748..d243fcd05a6 100644 --- a/lucene/core/src/java/org/apache/lucene/index/SegmentCoreReaders.java +++ b/lucene/core/src/java/org/apache/lucene/index/SegmentCoreReaders.java @@ -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 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 { diff --git a/lucene/core/src/java/org/apache/lucene/index/SegmentReader.java b/lucene/core/src/java/org/apache/lucene/index/SegmentReader.java index 985b0a11820..9bf7e692311 100644 --- a/lucene/core/src/java/org/apache/lucene/index/SegmentReader.java +++ b/lucene/core/src/java/org/apache/lucene/index/SegmentReader.java @@ -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 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 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 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 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); } /**