From 9313a6304b3d6560b6dce68ef4c0efaab52b22b8 Mon Sep 17 00:00:00 2001 From: Noble Paul Date: Fri, 15 Apr 2016 13:23:51 +0530 Subject: [PATCH] SOLR-8985: Added back support for 'includeDynamic' flag to /schema/fields endpoint --- solr/CHANGES.txt | 2 ++ .../org/apache/solr/schema/IndexSchema.java | 15 +++++++++++---- .../schema/TestFieldCollectionResource.java | 18 ++++++++++++++++-- 3 files changed, 29 insertions(+), 6 deletions(-) diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt index 9987ecb76a1..6152a92f117 100644 --- a/solr/CHANGES.txt +++ b/solr/CHANGES.txt @@ -164,6 +164,8 @@ Other Changes * SOLR-8967: In SolrCloud mode, under the 'Core Selector' dropdown in the UI the Replication tab won't be displayed anymore. The Replication tab is only beneficial to users running Solr in master-slave mode. (Varun Thacker) +* SOLR-8985: Added back support for 'includeDynamic' flag to /schema/fields endpoint (noble) + ================== 6.0.0 ================== Consult the LUCENE_CHANGES.txt file for additional, low level, changes in this release diff --git a/solr/core/src/java/org/apache/solr/schema/IndexSchema.java b/solr/core/src/java/org/apache/solr/schema/IndexSchema.java index 4319c3ebba3..7f7bd73b0ea 100644 --- a/solr/core/src/java/org/apache/solr/schema/IndexSchema.java +++ b/solr/core/src/java/org/apache/solr/schema/IndexSchema.java @@ -1385,16 +1385,23 @@ public class IndexSchema { for (String fieldName : fieldNames) { fieldProperties.add(fields.get(fieldName).getNamedPropertyValues(params.getBool("showDefaults", false))); } + if (params.getBool("includeDynamic", false)) { + fieldProperties.addAll(getDynamicFields(params)); + } topLevel.add(FIELDS, fieldProperties); + topLevel.add(DYNAMIC_FIELDS, getDynamicFields(params)); + topLevel.add(COPY_FIELDS, getCopyFieldProperties(false, null, null)); + return topLevel; + } + + private List> getDynamicFields(SolrParams params) { List> dynamicFieldProperties = new ArrayList<>(); - for (IndexSchema.DynamicField dynamicField : dynamicFields) { + for (DynamicField dynamicField : dynamicFields) { if ( ! dynamicField.getRegex().startsWith(INTERNAL_POLY_FIELD_PREFIX)) { // omit internal polyfields dynamicFieldProperties.add(dynamicField.getPrototype().getNamedPropertyValues(params.getBool("showDefaults", false))); } } - topLevel.add(DYNAMIC_FIELDS, dynamicFieldProperties); - topLevel.add(COPY_FIELDS, getCopyFieldProperties(false, null, null)); - return topLevel; + return dynamicFieldProperties; } /** diff --git a/solr/core/src/test/org/apache/solr/rest/schema/TestFieldCollectionResource.java b/solr/core/src/test/org/apache/solr/rest/schema/TestFieldCollectionResource.java index dd554158eab..6fdd29892bb 100644 --- a/solr/core/src/test/org/apache/solr/rest/schema/TestFieldCollectionResource.java +++ b/solr/core/src/test/org/apache/solr/rest/schema/TestFieldCollectionResource.java @@ -15,11 +15,9 @@ * limitations under the License. */ package org.apache.solr.rest.schema; -import com.carrotsearch.randomizedtesting.annotations.Seed; import org.apache.solr.rest.SolrRestletTestBase; import org.junit.Test; -import java.io.IOException; public class TestFieldCollectionResource extends SolrRestletTestBase { @Test @@ -39,4 +37,20 @@ public class TestFieldCollectionResource extends SolrRestletTestBase { "/fields/[2]/name=='_version_'"); } + + @Test + public void testJsonGetAllFieldsIncludeDynamic() throws Exception { + assertJQ("/schema/fields?indent=on&includeDynamic=true", + "/fields/[0]/name=='HTMLstandardtok'", + "/fields/[1]/name=='HTMLwhitetok'", + "/fields/[2]/name=='_version_'", + "/fields/[98]/name=='*_d'", + "/fields/[97]/name=='*_f'", + "/fields/[96]/name=='*_b'", + "/fields/[95]/name=='*_t'", + "/fields/[94]/name=='*_l'" + + ); + } + }