Apache Lucene open-source search software
LUCENE-8511: MultiFields.getIndexedFields optimize to not call getMergedFieldInfos
David Smiley4ccf0fb8f6ce
diff --git a/lucene/CHANGES.txt b/lucene/CHANGES.txtindex 70badd8e56e..d30575931cb 100644--- a/lucene/CHANGES.txt+++ b/lucene/CHANGES.txt@@ -170,6 +170,9 @@ Optimizations* LUCENE-8448: Boolean queries now propagates the mininum score to their sub-scorers.(Jim Ferenczi, Adrien Grand)+* LUCENE-8511: MultiFields.getIndexedFields is now optimized; does not call getMergedFieldInfos+ (David Smiley)+======================= Lucene 7.6.0 =======================Builddiff --git a/lucene/core/src/java/org/apache/lucene/index/MultiFields.java b/lucene/core/src/java/org/apache/lucene/index/MultiFields.javaindex 19078a83c15..32ce2fabbe6 100644--- a/lucene/core/src/java/org/apache/lucene/index/MultiFields.java+++ b/lucene/core/src/java/org/apache/lucene/index/MultiFields.java@@ -21,12 +21,13 @@ import java.io.IOException;import java.util.ArrayList;import java.util.Collection;import java.util.Collections;-import java.util.HashSet;import java.util.Iterator;import java.util.List;import java.util.Map;import java.util.Objects;import java.util.concurrent.ConcurrentHashMap;+import java.util.stream.Collectors;+import java.util.stream.StreamSupport;import org.apache.lucene.util.Bits;import org.apache.lucene.util.BytesRef;@@ -266,7 +267,8 @@ public final class MultiFields extends Fields {public static FieldInfos getMergedFieldInfos(IndexReader reader) {final String softDeletesField = reader.leaves().stream().map(l -> l.reader().getFieldInfos().getSoftDeletesField())- .filter(Objects::nonNull).findAny().orElse(null);+ .filter(Objects::nonNull)+ .findAny().orElse(null);final FieldInfos.Builder builder = new FieldInfos.Builder(new FieldInfos.FieldNumbers(softDeletesField));for(final LeafReaderContext ctx : reader.leaves()) {builder.add(ctx.reader().getFieldInfos());@@ -274,22 +276,13 @@ public final class MultiFields extends Fields {return builder.finish();}- /** Call this to get the (merged) FieldInfos representing the- * set of indexed fields <b>only</b> for a composite reader.- * <p>- * NOTE: the returned field numbers will likely not- * correspond to the actual field numbers in the underlying- * readers, and codec metadata ({@link FieldInfo#getAttribute(String)}- * will be unavailable.- */+ /** Returns a set of names of fields that have a terms index. The order is undefined. */public static Collection<String> getIndexedFields(IndexReader reader) {- final Collection<String> fields = new HashSet<>();- for(final FieldInfo fieldInfo : getMergedFieldInfos(reader)) {- if (fieldInfo.getIndexOptions() != IndexOptions.NONE) {- fields.add(fieldInfo.name);- }- }- return fields;+ return reader.leaves().stream()+ .flatMap(l -> StreamSupport.stream(l.reader().getFieldInfos().spliterator(), false)+ .filter(fi -> fi.getIndexOptions() != IndexOptions.NONE))+ .map(fi -> fi.name)+ .collect(Collectors.toSet());}private static class LeafReaderFields extends Fields {