diff --git a/solr/core/src/java/org/apache/solr/search/SolrDocumentFetcher.java b/solr/core/src/java/org/apache/solr/search/SolrDocumentFetcher.java index 3dbc6db1040..059efa43d09 100644 --- a/solr/core/src/java/org/apache/solr/search/SolrDocumentFetcher.java +++ b/solr/core/src/java/org/apache/solr/search/SolrDocumentFetcher.java @@ -59,6 +59,7 @@ import org.apache.lucene.index.StoredFieldVisitor; import org.apache.lucene.misc.document.LazyDocument; import org.apache.lucene.util.BytesRef; +import org.apache.lucene.util.CollectionUtil; import org.apache.lucene.util.NumericUtils; import org.apache.solr.common.SolrDocument; import org.apache.solr.common.SolrDocumentBase; @@ -567,7 +568,14 @@ public void decorateDocValueFields(SolrDocumentBase doc, int docid, Set declaredDynamicEventsFields = + getDeclaredDynamicEventsFields(localId, leafReader); for (String fieldName : fields) { + if (declaredDynamicEventsFields != null + && fieldName.startsWith("evt_") + && !declaredDynamicEventsFields.contains(fieldName)) { + continue; + } Object fieldValue = decodeDVField(localId, leafReader, fieldName); if (fieldValue != null) { doc.setField(fieldName, fieldValue); @@ -575,6 +583,47 @@ public void decorateDocValueFields(SolrDocumentBase doc, int docid, SetHere we pull the specific dynamic field names contained in this doc from a field that is + * populated in an UpdateRequestProcessor. + */ + private static Set getDeclaredDynamicEventsFields(int localId, LeafReader leafReader) + throws IOException { + final SortedSetDocValues dynamicEventsFields = + leafReader.getSortedSetDocValues("DynamicEventsFields"); + final Set hasDynamicEventsFields; + if (dynamicEventsFields == null || !dynamicEventsFields.advanceExact(localId)) { + return null; // legacy doc, no filtering + } else { + final int ct = dynamicEventsFields.docValueCount(); + final BytesRef firstHasFieldName = + dynamicEventsFields.lookupOrd(dynamicEventsFields.nextOrd()); + if (ct == 1) { + if (firstHasFieldName.length == 0) { + return Collections.emptySet(); + } else { + return Collections.singleton(firstHasFieldName.utf8ToString()); + } + } else { + hasDynamicEventsFields = CollectionUtil.newHashSet(ct); + assert firstHasFieldName.length != 0; + hasDynamicEventsFields.add(firstHasFieldName.utf8ToString()); + int i = ct - 1; + do { + hasDynamicEventsFields.add( + dynamicEventsFields.lookupOrd(dynamicEventsFields.nextOrd()).utf8ToString()); + } while (--i > 0); + return hasDynamicEventsFields; + } + } + } + /** * Decode value from DV field for a document *