epugh commented on code in PR #5412:
URL: https://github.com/apache/solr/pull/5412#discussion_r4769055904
##########
solr/core/src/test/org/apache/solr/handler/designer/TestSchemaDesigner.java:
##########
@@ -275,6 +278,153 @@ public void testAddTechproductsProgressively() throws
Exception {
}
}
+ @Test
+ public void testOpeningPublishedSchemaKeepsNestedDocsFields() throws
Exception {
+ String configSet = "publishedWithNestedDocs";
+ cc.getConfigSetService().copyConfig(DEFAULT_CONFIGSET_NAME, configSet);
+
assertTrue(helper.loadLatestSchema(configSet).hasExplicitField("_nest_path_"));
+
+ SchemaDesignerInfoResponse info = schemaDesigner.getInfo(configSet);
+ assertTrue(info.enableNestedDocs);
+
+ // the UI sends back the setting from getInfo when it opens the schema
+ when(mockReq.getContentStreams()).thenReturn(null);
+ SchemaDesignerResponse response =
+ schemaDesigner.analyze(
+ configSet, null, null, null, List.of("es"), true, true,
info.enableNestedDocs);
+ assertTrue(response.enableNestedDocs);
+
+ ManagedIndexSchema schema =
helper.loadLatestSchema(getMutableId(configSet));
+ assertTrue(schema.hasExplicitField("_nest_path_"));
+ assertTrue(schema.hasExplicitField("_root_"));
+ assertNotNull(schema.getFieldTypeByName("text_es"));
+ assertNotNull(schema.getFieldTypeByName("text_general_rev"));
+ }
+
+ @Test
+ public void testOpeningPublishedSchemaWithOnlyRootFieldKeepsIt() throws
Exception {
+ String configSet = "publishedWithRootOnly";
+ cc.getConfigSetService().copyConfig(DEFAULT_CONFIGSET_NAME, configSet);
+ ManagedIndexSchema published = helper.loadLatestSchema(configSet);
+ published.deleteFields(List.of("_nest_path_")).persistManagedSchema(false);
+
+ SchemaDesignerInfoResponse info = schemaDesigner.getInfo(configSet);
+ assertTrue(info.enableNestedDocs);
+
+ when(mockReq.getContentStreams()).thenReturn(null);
+ schemaDesigner.analyze(configSet, null, null, null, null, true, true,
info.enableNestedDocs);
+
+ ManagedIndexSchema schema =
helper.loadLatestSchema(getMutableId(configSet));
+ assertTrue(schema.hasExplicitField("_root_"));
+ assertFalse(schema.hasExplicitField("_nest_path_"));
+ }
+
+ @Test
+ public void testDisablingDynamicFieldsKeepsThoseTheSchemaNeeds() throws
Exception {
+ String configSet = "techproductsNoDynamic";
+ cc.getConfigSetService().uploadConfig(configSet,
ExternalPaths.TECHPRODUCTS_CONFIGSET);
+
+ when(mockReq.getContentStreams()).thenReturn(null);
+ schemaDesigner.analyze(configSet, null, null, null, null, false, null,
null);
+
+ ManagedIndexSchema schema =
helper.loadLatestSchema(getMutableId(configSet));
+ // copyField author -> author_s, and the currency type's amountLongSuffix
/ codeStrSuffix
+ assertNotNull(schema.getFieldOrNull("*_s"));
+ assertNotNull(schema.getFieldOrNull("*_l_ns"));
+ assertNotNull(schema.getFieldOrNull("*_s_ns"));
+ assertNull(schema.getFieldOrNull("*_i"));
+ }
+
+ @Test
+ public void testAnalyzeRollsBackChangesTheCollectionCannotLoad() throws
Exception {
+ String configSet = "rollbackOnLoadFailure";
+ cc.getConfigSetService().copyConfig(DEFAULT_CONFIGSET_NAME, configSet);
+ when(mockReq.getContentStreams()).thenReturn(null);
+ schemaDesigner.analyze(configSet, null, null, null, null, true, true,
true);
+
+ // text_general isn't a language type, so it survives language sync, but
the Spanish stopwords
+ // it now uses do not
+ String mutableId = getMutableId(configSet);
+ ManagedIndexSchema schema = helper.loadLatestSchema(mutableId);
+ Map<String, Object> analyzer =
+ Map.of(
+ "tokenizer",
+ Map.of("class", "solr.StandardTokenizerFactory"),
+ "filters",
+ List.of(Map.of("class", "solr.StopFilterFactory", "words",
"lang/stopwords_es.txt")));
+ schema
+ .replaceFieldType(
+ "text_general",
+ "solr.TextField",
+ Map.of("name", "text_general", "class", "solr.TextField",
"analyzer", analyzer))
+ .persistManagedSchema(false);
+ int version = helper.getCurrentSchemaVersion(mutableId);
+ // analyze re-creates the temp collection, and that fails to load the
schema
+
CollectionAdminRequest.deleteCollection(mutableId).process(cluster.getSolrClient());
+
+ SolrException exc =
+ expectThrows(
+ SolrException.class,
+ () ->
+ schemaDesigner.analyze(
+ configSet, version, null, null, List.of("en"), true, true,
true));
+ assertTrue(exc.getMessage(), exc.getMessage().contains("Changes were not
applied"));
+
+ schema = helper.loadLatestSchema(mutableId);
+ assertNotNull(schema.getFieldTypeByName("text_es"));
+ assertNotNull(
+ cc.getConfigSetService().downloadFileFromConfig(mutableId,
"lang/stopwords_es.txt"));
+ assertTrue(schemaDesigner.getInfo(configSet).languages.isEmpty());
+ }
+
+ @Test
+ public void testAnalyzeMastodonLikeStatuses() throws Exception {
+ // SOLR-16673: numeric ids, child objects that are null or empty in some
statuses, and fields
+ // that are always null, analyzed with nested docs disabled
+ String configSet = "mastodonStatuses";
+ String json =
Review Comment:
Multi line json?
##########
solr/solr-ref-guide/modules/indexing-guide/pages/schema-designer.adoc:
##########
@@ -172,6 +172,14 @@ For instance, to filter fields with `docValues` enabled,
choose `feature` and th
image::schema-designer/field-filters.png[image,width=500]
+[NOTE]
+====
+Every field found in your sample documents is listed as an explicit field,
including fields that already match a dynamic field.
+For example, a `genre_s` field in a sample document is added as an explicit
`genre_s` field even when the schema has a `*_s` dynamic field.
+This lets you see and edit every field from your data, but it also means the
published schema contains these fields.
+The Schema Designer can't delete fields, so if you want the dynamic field to
handle them instead, remove them after publishing with the
xref:schema-api.adoc#delete-a-field[Schema API].
Review Comment:
Is this an opportunity to reuse the schema api? Are there APIs in schema
designer that duplicate existing schema APIs?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]