You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@solr.apache.org by th...@apache.org on 2021/11/30 17:35:04 UTC
[solr] branch main updated: SOLR-15813: Schema designer not handling stored as a string (vs. boolean) in the config overlay (#435)
This is an automated email from the ASF dual-hosted git repository.
thelabdude pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/solr.git
The following commit(s) were added to refs/heads/main by this push:
new 470b7fb SOLR-15813: Schema designer not handling stored as a string (vs. boolean) in the config overlay (#435)
470b7fb is described below
commit 470b7fbff96aec0bd1120634f3f8a8241484f6f7
Author: Timothy Potter <th...@gmail.com>
AuthorDate: Tue Nov 30 10:33:38 2021 -0700
SOLR-15813: Schema designer not handling stored as a string (vs. boolean) in the config overlay (#435)
---
solr/CHANGES.txt | 2 ++
.../solr/handler/designer/SchemaDesignerSettings.java | 18 ++++++++++++++----
.../handler/designer/SchemaDesignerSettingsDAO.java | 11 ++---------
.../designer/TestSchemaDesignerSettingsDAO.java | 5 +++++
.../web/js/angular/controllers/schema-designer.js | 10 +++++-----
5 files changed, 28 insertions(+), 18 deletions(-)
diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt
index f156753..c5efe79 100644
--- a/solr/CHANGES.txt
+++ b/solr/CHANGES.txt
@@ -451,6 +451,8 @@ Bug Fixes
* SOLR-13900: Reset index values on authorization rules after deleting by index (Timothy Potter)
+* SOLR-15813: Schema designer not handling `update.autoCreateFields` stored as a string (vs. boolean) in the config overlay (Timothy Potter)
+
================== 8.11.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/handler/designer/SchemaDesignerSettings.java b/solr/core/src/java/org/apache/solr/handler/designer/SchemaDesignerSettings.java
index 756a26d..b567d5e 100644
--- a/solr/core/src/java/org/apache/solr/handler/designer/SchemaDesignerSettings.java
+++ b/solr/core/src/java/org/apache/solr/handler/designer/SchemaDesignerSettings.java
@@ -39,13 +39,23 @@ class SchemaDesignerSettings implements SchemaDesignerConstants {
@SuppressWarnings("unchecked")
SchemaDesignerSettings(Map<String, Object> stored) {
- this.isDisabled = (Boolean) stored.getOrDefault(DESIGNER_KEY + DISABLED, false);
+ this.isDisabled = getSettingAsBool(stored, DESIGNER_KEY + DISABLED, false);
this.publishedVersion = null;
this.copyFrom = (String) stored.get(DESIGNER_KEY + COPY_FROM_PARAM);
this.languages = (List<String>) stored.getOrDefault(DESIGNER_KEY + LANGUAGES_PARAM, Collections.emptyList());
- this.dynamicFieldsEnabled = (Boolean) stored.getOrDefault(DESIGNER_KEY + ENABLE_DYNAMIC_FIELDS_PARAM, true);
- this.nestedDocsEnabled = (Boolean) stored.getOrDefault(DESIGNER_KEY + ENABLE_NESTED_DOCS_PARAM, false);
- this.fieldGuessingEnabled = (Boolean) stored.getOrDefault(AUTO_CREATE_FIELDS, true);
+ this.dynamicFieldsEnabled = getSettingAsBool(stored, DESIGNER_KEY + ENABLE_DYNAMIC_FIELDS_PARAM, true);
+ this.nestedDocsEnabled = getSettingAsBool(stored, DESIGNER_KEY + ENABLE_NESTED_DOCS_PARAM, false);
+ this.fieldGuessingEnabled = getSettingAsBool(stored, AUTO_CREATE_FIELDS, true);
+ }
+
+ static boolean getSettingAsBool(final Map<String, Object> stored, final String key, final boolean defaultValue) {
+ boolean settingAsBool = defaultValue;
+ final Object settingValue = stored != null ? stored.get(key) : null;
+ if (settingValue != null) {
+ // covers either a Boolean or String object in the map
+ settingAsBool = Boolean.parseBoolean(settingValue.toString());
+ }
+ return settingAsBool;
}
Map<String, Object> toMap() {
diff --git a/solr/core/src/java/org/apache/solr/handler/designer/SchemaDesignerSettingsDAO.java b/solr/core/src/java/org/apache/solr/handler/designer/SchemaDesignerSettingsDAO.java
index 975c1b6..275f2ba 100644
--- a/solr/core/src/java/org/apache/solr/handler/designer/SchemaDesignerSettingsDAO.java
+++ b/solr/core/src/java/org/apache/solr/handler/designer/SchemaDesignerSettingsDAO.java
@@ -113,7 +113,7 @@ class SchemaDesignerSettingsDAO implements SchemaDesignerConstants {
log.error("Failed to get config overlay for {}", configSet, exc);
}
Map<String, Object> userProps = overlay != null ? overlay.getUserProps() : Collections.emptyMap();
- return (boolean) userProps.getOrDefault(DESIGNER_KEY + DISABLED, false);
+ return SchemaDesignerSettings.getSettingAsBool(userProps, DESIGNER_KEY + DISABLED, false);
}
@SuppressWarnings("unchecked")
@@ -142,15 +142,8 @@ class SchemaDesignerSettingsDAO implements SchemaDesignerConstants {
return false; // no URP chain, so can't be enabled
}
- boolean isEnabled = true;
ConfigOverlay overlay = solrConfig.getOverlay();
- if (overlay != null) {
- Map<String, Object> userProps = overlay.getUserProps();
- if (userProps != null) {
- isEnabled = (Boolean) userProps.getOrDefault(AUTO_CREATE_FIELDS, true);
- }
- }
- return isEnabled;
+ return overlay == null || SchemaDesignerSettings.getSettingAsBool(overlay.getUserProps(), AUTO_CREATE_FIELDS, true);
}
private boolean hasFieldGuessingURPChain(final SolrConfig solrConfig) {
diff --git a/solr/core/src/test/org/apache/solr/handler/designer/TestSchemaDesignerSettingsDAO.java b/solr/core/src/test/org/apache/solr/handler/designer/TestSchemaDesignerSettingsDAO.java
index f1a71d9..9480368 100644
--- a/solr/core/src/test/org/apache/solr/handler/designer/TestSchemaDesignerSettingsDAO.java
+++ b/solr/core/src/test/org/apache/solr/handler/designer/TestSchemaDesignerSettingsDAO.java
@@ -117,6 +117,11 @@ public class TestSchemaDesignerSettingsDAO extends SolrCloudTestCase implements
DESIGNER_KEY + LANGUAGES_PARAM, Collections.singletonList("en"));
assertDesignerSettings(expSettings, settings);
assertTrue("should be disabled", dao.isDesignerDisabled(configSet));
+
+ // handles booleans stored as strings in the overlay
+ Map<String,Object> stored = Map.of(AUTO_CREATE_FIELDS, "false");
+ settings = new SchemaDesignerSettings(stored);
+ assertFalse(settings.fieldGuessingEnabled());
}
protected void assertDesignerSettings(Map<String, Object> expectedMap, SchemaDesignerSettings actual) {
diff --git a/solr/webapp/web/js/angular/controllers/schema-designer.js b/solr/webapp/web/js/angular/controllers/schema-designer.js
index f81cc7b..0701344 100644
--- a/solr/webapp/web/js/angular/controllers/schema-designer.js
+++ b/solr/webapp/web/js/angular/controllers/schema-designer.js
@@ -258,7 +258,7 @@ solrAdminApp.controller('SchemaDesignerController', function ($scope, $timeout,
$scope.sampleMessage = "Please upload or paste some sample documents to build the '" + $scope.currentSchema + "' schema.";
}
}
- });
+ }, $scope.errorHandler);
};
$scope.showNewSchemaDialog = function () {
@@ -752,7 +752,7 @@ solrAdminApp.controller('SchemaDesignerController', function ($scope, $timeout,
$scope.schemaDiffExists = !(diff.fields == null && diff.fieldTypes == null && dynamicFields == null && diff.copyFields == null);
$scope.showDiff = true;
- });
+ }, $scope.errorHandler);
}
$scope.togglePublish = function (event) {
@@ -850,7 +850,7 @@ solrAdminApp.controller('SchemaDesignerController', function ($scope, $timeout,
if (data.analysis && data.analysis["field_names"]) {
$scope.result = processFieldAnalysisData(data.analysis["field_names"][field]);
}
- });
+ }, $scope.errorHandler);
};
$scope.changeLanguages = function () {
@@ -916,7 +916,7 @@ solrAdminApp.controller('SchemaDesignerController', function ($scope, $timeout,
$scope.showAnalysis = false;
$scope.selectNodeInTree(id);
}
- });
+ }, $scope.errorHandler);
};
function fieldNodes(src, type) {
@@ -1850,7 +1850,7 @@ solrAdminApp.controller('SchemaDesignerController', function ($scope, $timeout,
}
}
$scope.onSelectQueryResultsNode(nodeId);
- });
+ }, $scope.errorHandler);
};
$scope.toggleShowAnalysisJson = function () {